### Network configuration example Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/README.md Example JSON structure for networks.json, specifying contract addresses and start blocks for different networks. Use with --network flag. ```json { "mainnet": { "MyContract": { "address": "0x1234...", "startBlock": 12345678 } }, "sepolia": { "MyContract": { "address": "0x5678...", "startBlock": 1000000 } } } ``` -------------------------------- ### Subgraph Configuration Example Source: https://github.com/graphprotocol/graph-node/wiki/Parity-&-Truffle-workflow Example of how to specify the contract address and ABI in the subgraph.yaml file. ```yaml source: address: "0xF0909E9C610dC497260eB0729D181275251B467b" abi: Auction ``` -------------------------------- ### Example Response: Resume Deployment Source: https://github.com/graphprotocol/graph-node/blob/master/docs/graphman-graphql-api.md Example JSON response for the resume deployment mutation, indicating a successful operation. ```json { "data": { "deployment": { "resume": { "success": true } } } } ``` -------------------------------- ### Initialize and Run an Example Subgraph Locally Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/npm/README.md Create a new subgraph from an example, build it, and run it locally with a specified Ethereum RPC URL. ```bash gnd init --from-example ethereum-gravatar 'My new subgraph' new-subgraph cd new-subgraph gnd codegen gnd build gnd dev --ethereum-rpc 'mainnet:' ``` -------------------------------- ### Install Development Helpers Source: https://github.com/graphprotocol/graph-node/blob/master/CONTRIBUTING.md Installs necessary development tools like cargo-watch and rustfmt. ```sh cargo install cargo-watch rustup component add rustfmt ``` -------------------------------- ### Install Truffle Source: https://github.com/graphprotocol/graph-node/wiki/Parity-&-Truffle-workflow Installs the beta version of Truffle. It's recommended to uninstall any existing versions first. ```bash $ npm uninstall -g truffle $ npm install -g truffle@beta ``` -------------------------------- ### Example Response: Deployment Info Source: https://github.com/graphprotocol/graph-node/blob/master/docs/graphman-graphql-api.md Example JSON response for the deployment info query, showing the 'isPaused' status. ```json { "data": { "deployment": { "info": [ { "status": { "isPaused": false } } ] } } } ``` -------------------------------- ### Install The Graph CLI Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/npm/README.md Install the gnd package globally using npm. ```bash npm install -g @graphprotocol/gnd ``` -------------------------------- ### Run Parity on Custom Port Source: https://github.com/graphprotocol/graph-node/wiki/Parity-&-Truffle-workflow Starts the Parity client on a custom JSON-RPC port (7545 in this example) with specified accounts unlocked. ```bash $ parity --config dev --unsafe-expose --jsonrpc-cors="all" --unlock account1,account2,account3 --password ~/Desktop/password.txt --jsonrpc-port 7545 ``` -------------------------------- ### Example Response: Pause Deployment Source: https://github.com/graphprotocol/graph-node/blob/master/docs/graphman-graphql-api.md Example JSON response for the pause deployment mutation, indicating a successful operation. ```json { "data": { "deployment": { "pause": { "success": true } } } } ``` -------------------------------- ### Example Response: Restart Deployment Source: https://github.com/graphprotocol/graph-node/blob/master/docs/graphman-graphql-api.md Example JSON response for the restart deployment mutation, returning the unique execution ID for the long-running command. ```json { "data": { "deployment": { "restart": { "id": "UNIQUE_EXECUTION_ID" } } } } ``` -------------------------------- ### Example Response: Execution In Progress Source: https://github.com/graphprotocol/graph-node/blob/master/docs/graphman-graphql-api.md Example JSON response indicating that a long-running command execution is currently in the 'RUNNING' state. ```json { "data": { "execution": { "info": { "status": "RUNNING", "errorMessage": null } } } } ``` -------------------------------- ### TOML Configuration for Production Setups Source: https://context7.com/graphprotocol/graph-node/llms.txt Configure Graph Node using a TOML file for multi-chain, multi-shard, and multi-node production environments. This example shows primary and replica PostgreSQL connections, query-only nodes, and chain-specific RPC provider settings. ```toml # graph-node.toml [general] # Mark nodes matching this regex as query-only (no block ingestion) query = "query_node_.*" [store] [store.primary] connection = "postgresql://graph:${PGPASSWORD}@primary-db/graph-node" weight = 0 # 0 = send no direct queries; use replicas only pool_size = 10 [store.primary.replicas.repl1] connection = "postgresql://graph:${PGPASSWORD}@replica1/graph-node" weight = 1 [store.primary.replicas.repl2] connection = "postgresql://graph:${PGPASSWORD}@replica2/graph-node" weight = 1 [store.vip] connection = "postgresql://graph:${PGPASSWORD}@vip-db/graph-node" weight = 1 pool_size = [ { node = "index_node_.*", size = 20 }, { node = "query_node_.*", size = 80 } ] [chains] ingestor = "block_ingestor_node" cache_size = 500 [chains.mainnet] shard = "vip" amp = "ethereum-mainnet" # AMP network alias (optional) # Per-chain RPC tuning (all optional) json_rpc_timeout = 300 # seconds request_retries = 15 max_block_range_size = 2000 provider = [ { label = "alchemy", url = "https://eth-mainnet.alchemyapi.io/v2/KEY", features = ["archive", "traces"] }, { label = "infura", url = "https://mainnet.infura.io/v3/KEY", features = [] } ] [chains.near-mainnet] shard = "primary" protocol = "near" provider = [ { label = "near-firehose", details = { type = "firehose", url = "https://near.firehose.example.com", key = "API_KEY", features = ["compression", "filters"] } } ] [deployment] [[deployment.rule]] match = { name = "vip/.*" } shard = "vip" indexers = ["index_node_vip_0", "index_node_vip_1"] [[deployment.rule]] match = { network = ["xdai", "poa-core"] } indexers = ["index_node_other_0"] [[deployment.rule]] ``` -------------------------------- ### Indexer CLI Installation and Usage Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/docs/migrating-from-graph-cli.md Instructions for installing the indexer-cli and using gnd indexer commands for managing indexers. Requires graph-indexer on $PATH. ```bash npm install -g @graphprotocol/indexer-cli gnd indexer status --network arbitrum-one gnd indexer rules get all --network mainnet gnd indexer allocations get --network arbitrum-one ``` -------------------------------- ### Start Graph Node from Source Source: https://context7.com/graphprotocol/graph-node/llms.txt Set up the database and environment variables, then run Graph Node with specified RPC endpoints and IPFS daemon. ```bash # Create database (run once) psql -U postgres <" ] ``` -------------------------------- ### Configure File-Based Logs for Local Development Source: https://github.com/graphprotocol/graph-node/blob/master/docs/environment-variables.md Set up file-based logging for local development by specifying the backend and directory. This example also includes common graph-node startup arguments. ```bash mkdir -p ./graph-logs export GRAPH_LOG_STORE_BACKEND=file export GRAPH_LOG_STORE_FILE_DIR=./graph-logs graph-node \ --postgres-url postgresql://graph:pass@localhost/graph-node \ --ethereum-rpc mainnet:https://... \ --ipfs 127.0.0.1:5001 ``` -------------------------------- ### Deployment Head Metric Example Source: https://github.com/graphprotocol/graph-node/blob/master/docs/metrics.md Example of the deployment_head metric, which tracks the head block number for a deployment. This metric includes labels for deployment, network, and shard. ```protobuf deployment_head{deployment="QmaeWFYbPwmXEk7UuACmkqgPq2Pba5t2RYdJtEyvAUmrxg",network="mumbai",shard="primary"} 19509077 ``` -------------------------------- ### Install gnd CLI Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/README.md Build the gnd CLI from source using Cargo. The executable will be located in `target/release/gnd`. ```bash cargo build -p gnd --release ``` -------------------------------- ### Basic Command Migration: graph-cli to gnd Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/docs/migrating-from-graph-cli.md For most users, migration is straightforward by replacing 'graph' with 'gnd'. This example shows the basic command replacements for codegen, build, and deploy. ```bash # Instead of: graph codegen graph build graph deploy --studio my-subgraph # Use: gnd codegen gnd build gnd deploy my-subgraph # defaults to Studio; prompts for version label in interactive terminals ``` -------------------------------- ### Graphman GraphQL API: Setup Source: https://context7.com/graphprotocol/graph-node/llms.txt Set the authentication token and port for the Graphman GraphQL API. This enables programmatic management of deployments. ```bash export GRAPHMAN_SERVER_AUTH_TOKEN=my-secret-token export GRAPHMAN_PORT=8050 ``` -------------------------------- ### Install AssemblyScript v0.6 Source: https://github.com/graphprotocol/graph-node/blob/master/runtime/test/README.md Use this command to install the specific v0.6 version of the AssemblyScript compiler required for API version 0.0.4 tests. ```bash npm install -g AssemblyScript/assemblyscript#v0.6 ``` -------------------------------- ### Installing Prettier for Formatting Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/docs/migrating-from-graph-cli.md The 'gnd codegen' command relies on Prettier for code formatting. Install it globally using npm or pnpm if it's not found. ```bash npm install -g prettier # or pnpm add -g prettier ``` -------------------------------- ### Run Integration Tests with Nix Source: https://github.com/graphprotocol/graph-node/blob/master/CLAUDE.md Start all necessary services for integration tests using Nix. This includes PostgreSQL, IPFS, and Anvil. Ensure these services are running in a separate terminal. ```bash # Human: Start all services for integration tests in a separate terminal # PostgreSQL: localhost:3011, IPFS: localhost:3001, Anvil: localhost:3021 nix run .#integration ``` -------------------------------- ### Initialize a New Subgraph Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/README.md Create a new subgraph project with basic scaffolding. Supports interactive mode or initialization from a contract, example, or existing subgraph. ```bash gnd init [SUBGRAPH_NAME] [DIRECTORY] ``` ```bash # Interactive mode (prompts for all options) gnd init ``` ```bash # From contract with ABI fetched from Etherscan gnd init --from-contract 0x1234... --network mainnet my-subgraph ``` ```bash # From contract with local ABI gnd init --from-contract 0x1234... --abi ./MyContract.json my-subgraph ``` ```bash # From an existing deployed subgraph gnd init --from-subgraph QmHash... my-subgraph ``` -------------------------------- ### Manage indexing rules Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/README.md Get all indexing rules or set a specific rule for a deployment on a given network. ```bash gnd indexer rules get all --network mainnet ``` ```bash gnd indexer rules set decisionBasis always --network mainnet ``` -------------------------------- ### Launch Postgres and IPFS with Docker Compose Source: https://github.com/graphprotocol/graph-node/blob/master/store/test-store/README.md Use this script to launch the required test dependencies, including Postgres and IPFS. It can optionally clean previous data before starting. ```shell ./store/test-store/devel/up.sh ``` ```shell ./store/test-store/devel/up.sh -c ``` -------------------------------- ### Run Graph Node Source: https://github.com/graphprotocol/graph-node/wiki/Parity-&-Truffle-workflow Starts the Graph Node with specified PostgreSQL URL, Ethereum RPC endpoint, and IPFS host. Ensure IPFS is running. ```bash $ cargo run -p graph-node --release -- \ --postgres-url postgresql://[ADMIN]@localhost:5432/subgraph-name \ --ethereum-rpc parity:http://127.0.0.1:8545 \ --ipfs 127.0.0.1:5001 ``` -------------------------------- ### JSON Examples for ethCall Function Signatures Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/docs/gnd-test.md Illustrates the required format for specifying function signatures, including input and return types, when mocking contract calls. ```json { "function": "symbol()(string)", // No inputs, returns string "function": "balanceOf(address)(uint256)", // One input, returns uint256 "function": "decimals()(uint8)" // No inputs, returns uint8 } ``` -------------------------------- ### Create and Configure PostgreSQL Database for Graph Node Source: https://github.com/graphprotocol/graph-node/blob/master/README.md Use these SQL commands to create a dedicated user, database, and necessary extensions for graph-node. Ensure the SUPERUSER is correct for your PostgreSQL installation. ```bash psql -U <'; create database "graph-node" with owner=graph template=template0 encoding='UTF8' locale='C'; create extension pg_trgm; create extension btree_gist; create extension postgres_fdw; grant usage on foreign data wrapper postgres_fdw to graph; EOF ``` -------------------------------- ### Describe Deployment by Hash Source: https://github.com/graphprotocol/graph-node/blob/master/docs/graphman.md Use this command to view details of a deployment specified by its IPFS hash. Requires a configuration file. ```bash graphman --config config.toml info QmfWRZCjT8pri4Amey3e3mb2Bga75Vuh2fPYyNVnmPYL66 ``` -------------------------------- ### Example Response: Execution Completed Source: https://github.com/graphprotocol/graph-node/blob/master/docs/graphman-graphql-api.md Example JSON response indicating that a long-running command execution has successfully completed with the 'SUCCEEDED' status. ```json { "data": { "execution": { "info": { "status": "SUCCEEDED", "errorMessage": null } } } } ``` -------------------------------- ### Describe Deployment with Status Source: https://github.com/graphprotocol/graph-node/blob/master/docs/graphman.md Use this command to view deployment details including status information (synced, health, block numbers). Requires a configuration file. ```bash graphman --config config.toml info QmfWRZCjT8pri4Amey3e3mb2Bga75Vuh2fPYyNVnmPYL66 --status ``` -------------------------------- ### Subgraph Features Response Example Source: https://github.com/graphprotocol/graph-node/blob/master/NEWS.md Example JSON response for the `subgraphFeatures` GraphQL query, indicating the features enabled for a subgraph and any errors encountered. ```json { "data": { "subgraphFeatures": { "errors": [], "features": ["nonFatalErrors", "ipfsOnEthereumContracts"] } } } ``` -------------------------------- ### Install AssemblyScript v0.19.10 Source: https://github.com/graphprotocol/graph-node/blob/master/runtime/test/README.md Install the specific v0.19.10 version of the AssemblyScript compiler for API version 0.0.5 tests. The latest version may also work. ```bash # for the precise one npm install -g assemblyscript@0.19.10 # for the latest one, it should work as well npm install -g assemblyscript ``` -------------------------------- ### Initialize a New Subgraph with gnd Source: https://context7.com/graphprotocol/graph-node/llms.txt Start a new subgraph project using the gnd CLI, initializing from a smart contract on a specified network. The --index-events flag is used for event indexing. ```bash gnd init --from-contract 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f \ --network mainnet \ --index-events \ uniswap-v2 ``` -------------------------------- ### Ethereum Chain Head Number Metric Example Source: https://github.com/graphprotocol/graph-node/blob/master/docs/metrics.md Example of the ethereum_chain_head_number metric, indicating the block number of the most recent block synced from Ethereum. It includes a network label. ```protobuf ethereum_chain_head_number{network="mumbai"} 20045294 ``` -------------------------------- ### Nested Entity Query Example Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/docs/gnd-test.md Illustrates how to test relationships and nested entities in subgraph queries. This example queries accounts and their associated balances, including nested token symbols. ```json { "query": "{ accounts { id balances { token { symbol } amount } } }", "expected": { "accounts": [ { "id": "0xbbbb...", "balances": [ { "token": { "symbol": "GRT" }, "amount": "5000000000000000000" } ] } ] } } ``` -------------------------------- ### Subgraph Data Source Binding Example Source: https://github.com/graphprotocol/graph-node/blob/master/docs/specs/gnd-cli-expansion.md Example of a subgraph data source configuration in a manifest file. gnd generates types based on the `name` field for stable import paths. ```yaml dataSources: - kind: subgraph name: SourceSubgraph source: address: "QmRWTEejPDDwALaquFGm6X2GBbbh5osYDXwCRRkoZ6KQhb" ``` -------------------------------- ### Describe Deployment by Name Source: https://github.com/graphprotocol/graph-node/blob/master/docs/graphman.md Use this command to view details of a deployment specified by its subgraph name. Requires a configuration file. ```bash graphman --config config.toml info subgraph-name ``` -------------------------------- ### Build and Run Graph Node from Source Source: https://github.com/graphprotocol/graph-node/blob/master/README.md Compile and run the graph-node executable with specified configurations for logging, PostgreSQL connection, Ethereum RPC endpoints, and IPFS. The --release flag enables optimizations. ```bash export GRAPH_LOG=debug cargo run -p graph-node --release -- \ --postgres-url $POSTGRES_URL \ --ethereum-rpc NETWORK_NAME:[CAPABILITIES]:URL \ --ipfs 127.0.0.1:5001 ``` -------------------------------- ### Set Start Block for AMP Subgraph Indexing Source: https://github.com/graphprotocol/graph-node/blob/master/docs/amp-powered-subgraphs.md Define the minimum block number for SQL queries in an AMP data source. This serves as the starting point for the indexing process. Defaults to block 0 if not provided. ```yaml dataSources: - kind: amp name: Transfers network: ethereum-mainnet source: startBlock: 11446769 dataset: edgeandnode/ethereum_mainnet tables: - blocks - transactions transformer: apiVersion: 0.0.1 tables: - name: Transfer file: ``` -------------------------------- ### Elasticsearch Retention Policy Example Source: https://github.com/graphprotocol/graph-node/blob/master/docs/log-store.md Define an Elasticsearch Index Lifecycle Management (ILM) policy to manage log data retention. This example sets up hot, warm, and delete phases, retaining data for 30 days. ```json { "policy": "graph-logs-policy", "phases": { "hot": { "min_age": "0ms", "actions": {} }, "warm": { "min_age": "7d", "actions": {} }, "delete": { "min_age": "30d", "actions": { "delete": {} } } } } ``` -------------------------------- ### Configure Multiple PostgreSQL Databases and Replicas Source: https://github.com/graphprotocol/graph-node/blob/master/docs/config.md Define multiple PostgreSQL shards and their read replicas within the [store] section. This setup allows for distributing storage and query load across different databases. Environment variables in connection strings are expanded before use. ```toml [store] [store.primary] connection = "postgresql://graph:${PGPASSWORD}@primary/graph" weight = 0 pool_size = 10 [store.primary.replicas.repl1] connection = "postgresql://graph:${PGPASSWORD}@primary-repl1/graph" weight = 1 [store.primary.replicas.repl2] connection = "postgresql://graph:${PGPASSWORD}@primary-repl2/graph" weight = 1 [store.vip] connection = "postgresql://graph:${PGPASSWORD}@${VIP_MAIN}/graph" weight = 1 pool_size = 10 [store.vip.replicas.repl1] connection = "postgresql://graph:${PGPASSWORD}@${VIP_REPL1}/graph" weight = 1 ``` -------------------------------- ### Check graph-indexer version Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/README.md Display the version of the installed graph-indexer. ```bash gnd indexer version ``` -------------------------------- ### Checking gnd Version Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/docs/migrating-from-graph-cli.md Verify the installed version of the gnd CLI. ```bash gnd --version ``` -------------------------------- ### Manage cost models Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/README.md Get cost model information for the indexer. ```bash gnd indexer cost get ``` -------------------------------- ### Quick Start: Subgraph Development Workflow Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/README.md A typical workflow for developing a subgraph, from initialization to deployment. This includes creating a subgraph from a contract, generating types, building, and deploying locally or to Subgraph Studio. ```bash # Create a new subgraph from a contract gnd init --from-contract 0x1234... --network mainnet my-subgraph # Generate AssemblyScript types gnd codegen # Build the subgraph gnd build # Deploy to a local Graph Node gnd create --node http://localhost:8020 my-name/my-subgraph gnd deploy --node http://localhost:8020 --ipfs http://localhost:5001 -l v0.0.1 my-name/my-subgraph # Or deploy to Subgraph Studio gnd auth YOUR_DEPLOY_KEY gnd deploy -l v0.0.1 my-name/my-subgraph ``` -------------------------------- ### Querying Logs using cURL Source: https://github.com/graphprotocol/graph-node/blob/master/docs/log-store.md Example of how to query the logs store using a cURL command. ```APIDOC ## Querying the logs store using cURL ```bash curl -X POST http://localhost:8000/subgraphs/id/ \ -H "Content-Type: application/json" \ -d '{ "query": "{ _logs(level: ERROR, first: 10) { timestamp level text } }" }' ``` ``` -------------------------------- ### View available indexer commands Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/README.md Display all available commands for the indexer subcommand. Requires graph-indexer to be installed. ```bash gnd indexer help ``` -------------------------------- ### Compile Contracts with Truffle Source: https://github.com/graphprotocol/graph-node/wiki/Parity-&-Truffle-workflow Compiles smart contracts using Truffle. ```bash $ truffle compile ``` -------------------------------- ### Run Unit Tests with Nix Source: https://github.com/graphprotocol/graph-node/blob/master/CLAUDE.md Execute unit tests using the Nix package manager. Ensure PostgreSQL and IPFS are running in a separate terminal. ```bash # Human: Start PostgreSQL + IPFS for unit tests in a separate terminal # PostgreSQL: localhost:5432, IPFS: localhost:5001 nix run .#unit # Claude: Run unit tests just test-unit ``` -------------------------------- ### gnd Version Output Source: https://github.com/graphprotocol/graph-node/blob/master/docs/specs/gnd-cli-expansion.md Example of the version output for the gnd CLI, indicating both gnd and compatible graph-cli versions. ```bash $ gnd --version gnd 0.1.0 (graph-cli compatible: 0.98.1) ``` -------------------------------- ### Flag Compatibility: deploy Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/docs/migrating-from-graph-cli.md Demonstrates that the 'deploy' command and its flags are compatible between graph-cli and gnd. ```bash graph deploy -l v1.0.0 --ipfs http://localhost:5001 my-subgraph gnd deploy -l v1.0.0 --ipfs http://localhost:5001 my-subgraph ``` -------------------------------- ### Publish a Subgraph to The Graph Network Source: https://context7.com/graphprotocol/graph-node/llms.txt Authenticate with your deployment key and publish your subgraph to a decentralized network. Ensure you have the graph-indexer installed for this functionality. ```bash gnd auth YOUR_DEPLOY_KEY gnd publish --protocol-network arbitrum-one ``` -------------------------------- ### Querying Hourly Aggregated Stats Source: https://context7.com/graphprotocol/graph-node/llms.txt Example GraphQL query to retrieve hourly token statistics, including filtering by token and timestamp. ```graphql # Query hourly stats for a token, including the current unfinished bucket { tokenStats( interval: "hour" current: include where: { token: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" timestamp_gte: "1704067200000000" } ) { timestamp totalVolume avgPrice tradeCount } } ``` -------------------------------- ### graph-node Management with graphman Source: https://github.com/graphprotocol/graph-node/blob/master/gnd/docs/migrating-from-graph-cli.md Demonstrates the alternative to 'graph node' commands using 'graphman' for node management operations. ```bash # Instead of graph node commands, use graphman: graphman info subgraph-name graphman reassign subgraph-name shard ``` -------------------------------- ### Configure File-Based Logs Source: https://context7.com/graphprotocol/graph-node/llms.txt Use this command to set up file-based logging for local development. Ensure the log directory exists. ```bash cargo run -p graph-node --release -- \ --postgres-url $POSTGRES_URL \ --ethereum-rpc mainnet:https://... \ --ipfs 127.0.0.1:5001 \ --log-store-backend file \ --log-store-file-dir ./graph-logs ```