### Python Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/token-api/quick-start.mdx Example of how to fetch EVM balances using Python requests. ```python import requests res = requests.get( "https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208", headers={"Authorization": "Bearer YOUR_TOKEN"}, ) print(res.json()) ``` -------------------------------- ### Verify Graph CLI installation Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/quick-start.mdx Checks the installed version of the Graph CLI. ```bash graph --version ``` -------------------------------- ### Go Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/token-api/quick-start.mdx Example of how to fetch EVM balances using Go's net/http package. ```go package main import ( "fmt" "encoding/json" "net/http" ) func main() { req, _ := http.NewRequest("GET", "https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208", nil, ) req.Header.Set("Authorization", "Bearer YOUR_TOKEN") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() var data any json.NewDecoder(res.Body).Decode(&data) fmt.Printf("%#v\n", data) } ``` -------------------------------- ### Initialize a new Subgraph from an example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/developing/creating/install-the-cli.mdx Command to initialize a new subgraph project using a provided example subgraph. ```bash graph init --from-example=example-subgraph ``` -------------------------------- ### Node.js Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/token-api/quick-start.mdx Example of how to fetch EVM balances using the TypeScript Node.js SDK. ```typescript import {EVMChains, TokenAPI} from "@pinax/token-api"; const client = new TokenAPI({ apiToken: process.env.TOKEN_API_KEY || "" }); const result = await client.evm.tokens.getBalances({ network: EVMChains.Ethereum, address: ['0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208'] }) ``` -------------------------------- ### Rust Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/token-api/quick-start.mdx Example of how to fetch EVM balances using Rust's reqwest library. ```rust use reqwest::Client; #[tokio::main] async fn main() -> reqwest::Result<()> { let res = Client::new() .get("https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208") .bearer_auth("YOUR_TOKEN") .send() .await?; println!("{}", res.text().await?); Ok(()) } ``` -------------------------------- ### Docker Compose Configuration Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/indexing/tap.mdx An example Docker Compose configuration for deploying the indexer-service and tap-agent. ```yaml services: indexer-service: image: ghcr.io/graphprotocol/indexer-service-rs:latest ports: - '7600:7600' - '7300:7300' volumes: - ./config.toml:/config.toml command: ['--config', '/config.toml'] environment: - RUST_LOG=indexer_service=info restart: unless-stopped tap-agent: image: ghcr.io/graphprotocol/indexer-tap-agent:latest ports: - '7301:7300' volumes: - ./config.toml:/config.toml command: ['--config', '/config.toml'] environment: - RUST_LOG=indexer_tap_agent=info restart: unless-stopped ``` -------------------------------- ### cURL Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/token-api/quick-start.mdx Example of how to fetch EVM balances using cURL with an API token. ```shell curl --request GET \ --url "https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208" \ --header 'Accept: application/json' \ --header 'Authorization: Bearer YOUR_TOKEN' ``` -------------------------------- ### Setup PostgreSQL database Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/indexing/tooling/graph-node.mdx Steps to initialize and start a PostgreSQL database for Graph Node. ```shell initdb -D .postgres pg_ctl -D .postgres -l logfile start createdb graph-node ``` -------------------------------- ### TAP Agent Configuration Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/indexing/tap.mdx A TOML configuration file example for the indexer-service-rs and indexer-tap-agent, demonstrating various settings for network, database, blockchain, and TAP-specific configurations. ```toml [indexer] indexer_address = "0x1111111111111111111111111111111111111111" operator_mnemonic = "your twelve word mnemonic phrase here ..." # For key rotation, you can specify multiple mnemonics. # All configured mnemonics are tried when creating attestation signers, # allowing allocations created with different operator keys to work. # The first mnemonic is used as the primary identity on the /info endpoint. # operator_mnemonics = [ # "previous mnemonic phrase here if you rotated keys" # ] [database] postgres_url = "postgresql://user:password@localhost:5432/indexer_db" [graph_node] query_url = "http://graph-node:8000" status_url = "http://graph-node:8000/graphql" [subgraphs.network] # The Graph Network Subgraph (includes escrow data for Horizon) # Use query_url for hosted service, or deployment_id for local indexing (recommended) query_url = "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-arbitrum" # deployment_id = "QmUVskWrz1ZiQZ76AtyhcfFDEH1ELnRpoyEhVL8p6NFTbR" [blockchain] chain_id = 42161 receipts_verifier_address_v2 = "0x8f69F5C07477Ac46FBc491B1E6D91E2be0111A9e" subgraph_service_address = "0xb2Bb92d0DE618878E438b55D5846cfecD9301105" # Legacy V1 verifier (deprecated in v2.0.0, can be removed from your config): # receipts_verifier_address = "0x33f9E93266ce0E108fc85DdE2f71dab555A0F05a" # For testnet: # chain_id = 421614 # receipts_verifier_address_v2 = "0x382863e7B662027117449bd2c49285582bbBd21B" # subgraph_service_address = "0xc24A3dAC5d06d771f657A48B20cE1a671B78f26b" [tap] max_amount_willing_to_lose_grt = "0.1" [tap.sender_aggregator_endpoints] # Mainnet gateways "0xDDE4cfFd3D9052A9cb618fC05a1Cd02be1f2F467" = "https://tap-aggregator.network.thegraph.com" "0xDD6a6f76eb36B873C1C184e8b9b9e762FE216490" = "https://tap-aggregator-arbitrum-one.graphops.xyz" # For testnet: # "0xC3dDf37906724732FfD748057FEBe23379b0710D" = "https://tap-aggregator.testnet.thegraph.com" [horizon] enabled = true ``` -------------------------------- ### Setup Graph Node from source Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/indexing/overview.mdx Commands to set up and start a PostgreSQL database server, clone the Graph Node repository, build the source, and run the Graph Node. ```sh initdb -D .postgres pg_ctl -D .postgres -l logfile start createdb graph-node ``` ```sh cargo run -p graph-node --release -- \ --postgres-url postgresql://[USERNAME]:[PASSWORD]@localhost:5432/graph-node \ --ethereum-rpc [NETWORK_NAME]:[URL] \ --ipfs https://ipfs.thegraph.com ``` -------------------------------- ### Install URQL Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/querying/from-an-application.mdx Install the necessary packages for URQL. ```sh npm install urql graphql ``` -------------------------------- ### Install Apollo Client Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/querying/from-an-application.mdx Install the necessary packages for Apollo Client. ```sh npm install @apollo/client graphql ``` -------------------------------- ### Install PostgreSQL on MacOS Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/developing/creating/unit-testing-framework.mdx Installation command for PostgreSQL on MacOS. ```sh brew install postgresql ``` -------------------------------- ### Action Queue CLI Commands Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/indexing/overview.mdx Examples of using the indexer-cli to manage the action queue, including getting actions, queuing, approving, and canceling. ```bash graph indexer actions get all graph indexer actions get --status queued graph indexer actions queue allocate QmeqJ6hsdyk9dVbo1tvRgAxWrVS3rkERiEMsxzPShKLco6 5000 graph indexer actions queue reallocate QmeqJ6hsdyk9dVbo1tvRgAxWrVS3rkERiEMsxzPShKLco6 0x4a58d33e27d3acbaecc92c15101fbc82f47c2ae5 55000 graph indexer actions queue unallocate QmeqJ6hsdyk9dVbo1tvRgAxWrVS3rkERiEMsxzPShKLco6 0x4a58d33e27d3acbaecc92c15101fbc82f47c2ae graph indexer actions cancel graph indexer actions approve 1 3 5 graph indexer actions execute approve ``` -------------------------------- ### Example Subgraph Manifest Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/glossary.mdx An example of a subgraph.yaml file. ```yaml https://github.com/graphprotocol/example-subgraph/blob/master/subgraph.yaml ``` -------------------------------- ### x402 Payment - Typed SDK Setup Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/guides/x402-payments.mdx Install necessary packages for the typed SDK. ```bash npm install @graphprotocol/client-cli @graphprotocol/client-x402 ``` -------------------------------- ### Install dependencies Source: https://github.com/graphprotocol/docs/blob/main/README.md Installs all necessary project dependencies using pnpm. ```bash pnpm install ``` -------------------------------- ### Example `metadata.json` Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/developing/creating/unit-testing-framework.mdx This snippet shows an example metadata.json file. ```json { "startTime": 1, "endTime": 1, "periods": 1, "releaseStartTime": 1 } ``` -------------------------------- ### Get Sink Configuration Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/ai-suite/substreams-mcp/search.mdx Example of how to get a package's sink configuration and generate CLI commands. ```javascript get_sink_config("https://spkg.io/creator/package-v1.0.0.spkg") ``` -------------------------------- ### Duplicate Directives Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Shows an invalid example where a directive is used more than once at the same location. ```graphql query { dog { name @include(true) @include(true) } } ``` -------------------------------- ### Build Subgraph Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/quick-start.mdx Generates code and builds the Subgraph. ```bash graph codegen && graph build ``` -------------------------------- ### Invalid Fragment Definition Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Shows examples of invalid fragment definitions on scalar types or non-subtypes. ```graphql fragment fragOnScalar on Int { # we cannot define a fragment upon a scalar (`Int`) something } fragment inlineFragOnScalar on Dog { ... on Boolean { # `Boolean` is not a subtype of `Dog` somethingElse } } ``` -------------------------------- ### Run the project locally Source: https://github.com/graphprotocol/docs/blob/main/README.md Starts the development server for the documentation website. ```bash pnpm dev ``` -------------------------------- ### Install libpq on WSL Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/developing/creating/unit-testing-framework.mdx Install libpq development files on WSL. ```sh sudo apt-get install libpq-dev ``` -------------------------------- ### Incorrect Argument Values Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Shows examples of queries with hard-coded values that do not match the schema types. ```graphql query purposes { # If "name" is defined as "String" in the schema, # this query will fail during validation. purpose(name: 1) { id } } # This might also happen when an incorrect variable is defined: query purposes($name: Int!) { # If "name" is defined as `String` in the schema, # this query will fail during validation, because the # variable used is of type `Int` purpose(name: $name) { id } } ``` -------------------------------- ### Duplicate Fragment Name Example (Invalid) Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx An example of an invalid GraphQL operation violating the UniqueFragmentNamesRule due to duplicate fragment names. ```graphql # The following operation violated the UniqueFragmentName ``` -------------------------------- ### Duplicate Query Name Example (Invalid) Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx An example of an invalid GraphQL operation violating the UniqueOperationNamesRule due to duplicate query names. ```graphql query myData { id } query myData { name } ``` -------------------------------- ### Initialize a new Subgraph from an existing contract Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/developing/creating/install-the-cli.mdx Command to initialize a new subgraph project by indexing events from an existing smart contract. ```bash graph init \ --product subgraph-studio --from-contract \ [--network ] \ [--abi ] \ [] ``` -------------------------------- ### Initialize a Subgraph Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/quick-start.mdx Initializes a new Subgraph from an existing contract. ```bash graph init ``` -------------------------------- ### Unused Fragment Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Example of an operation with an unused fragment and its solution. ```graphql # Invalid, because fragment AllFields is never used. query something { someData } fragment AllFields { # unused :( name age } ``` ```graphql # Invalid, because fragment AllFields is never used. query something { someData } # remove the `AllFields` fragment ``` -------------------------------- ### Unused Variable Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Example of an operation with an unused variable and its solution. ```graphql # Invalid, because $someVar is never used. query something($someVar: String) { someData } ``` ```graphql query something { someData } ``` -------------------------------- ### Missing Selection-Set Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Illustrates a missing selection-set for an object field. ```graphql query { user { id image # `image` requires a Selection-Set for sub-fields! } } ``` -------------------------------- ### Install Graph Client CLI Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/querying/from-an-application.mdx Install The Graph Client CLI in your project. ```sh yarn add -D @graphprotocol/client-cli # or, with NPM: npm install --save-dev @graphprotocol/client-cli ``` -------------------------------- ### Conflicting Fields with Directives Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Example of fields with directives causing ambiguity and its solution. ```graphql fragment mergeSameFieldsWithSameDirectives on Dog { name @include(if: true) name @include(if: false) } ``` -------------------------------- ### Install PostgreSQL on Linux Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/developing/creating/unit-testing-framework.mdx Installation command for PostgreSQL on Linux, which depends on the distribution. ```sh sudo apt install postgresql ``` -------------------------------- ### Conflicting Fragments Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Example of two fragments causing a field conflict and its solution. ```graphql query { # Eventually, we have two "x" definitions, pointing # to different fields! ...A ...B } fragment A on Type { x: a } fragment B on Type { x: b } ``` -------------------------------- ### Conflicting Field Aliases Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Example of aliasing fields causing conflicts and its solution. ```graphql query { dogs { name: nickname name } } ``` ```graphql query { dogs { name: nickname originalName: name # alias the original `name` field } } ``` -------------------------------- ### Initialize Your Subgraph Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/developing/deploying/using-subgraph-studio.mdx Initializes your subgraph code through the CLI. ```bash graph init ``` -------------------------------- ### Duplicate Argument Name Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Example of an operation with duplicate argument names and its solution. ```graphql query myData($id: ID!) { userById(id: $id, id: "1") { id } } ``` ```graphql query myData($id: ID!) { userById(id: $id) { id } } ``` -------------------------------- ### Authenticate for Deployment Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/quick-start.mdx Authenticates the CLI with a deploy key obtained from Subgraph Studio. ```bash graph auth ``` -------------------------------- ### Docker Images Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/indexing/tap.mdx Docker images for indexer-service-rs and indexer-tap-agent. ```bash docker pull ghcr.io/graphprotocol/indexer-service-rs:latest docker pull ghcr.io/graphprotocol/indexer-tap-agent:latest ``` -------------------------------- ### Duplicate Variable Names Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Example of an operation with duplicate variable names and its solution. ```graphql query myData($id: String, $id: Int) { id ...MyFields } ``` ```graphql query myData($id: String) { # keep the relevant variable (here: `$id: String`) id ...MyFields } ``` -------------------------------- ### Duplicate Fragment Names Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Example of an operation with duplicate fragment names and its solution. ```graphql query myData { id ...MyFields } fragment MyFields { metadata } fragment MyFields { name } ``` ```graphql query myData { id ...MyFieldsName ...MyFieldsMetadata } fragment MyFieldsMetadata { # assign a unique name to fragment metadata } fragment MyFieldsName { # assign a unique name to fragment name } ``` -------------------------------- ### Install Cana CLI Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/guides/contract-analyzer.mdx Use npm to install it globally. ```bash npm install -g contract-analyzer ``` -------------------------------- ### Invalid Selection-Set Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Demonstrates an invalid selection-set where a scalar field is treated as an object. ```graphql query { user { id { # Invalid, because "id" is of type ID and does not have sub-fields } } } ``` -------------------------------- ### Set Delegation Parameters Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/indexing/overview.mdx Example of how to call the setDelegationParameters function to configure reward and fee distribution. ```solidity setDelegationParameters(950000, 600000, 500) ``` -------------------------------- ### Example package.json for WSL Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/developing/creating/unit-testing-framework.mdx Example package.json script for running tests on WSL, ensuring the local graph-cli is used. ```json { "name": "demo-subgraph", "version": "0.1.0", "scripts": { "test": "graph test", ... }, "dependencies": { "@graphprotocol/graph-cli": "^0.56.0", "@graphprotocol/graph-ts": "^0.31.0", "matchstick-as": "^0.6.0" } } ``` -------------------------------- ### Conflicting Fields with Arguments Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Example of fields with different arguments causing conflicts and its solution. ```graphql query { dogs { doesKnowCommand(dogCommand: SIT) doesKnowCommand(dogCommand: HEEL) } } ``` ```graphql query { dogs { knowsHowToSit: doesKnowCommand(dogCommand: SIT) knowsHowToHeel: doesKnowCommand(dogCommand: HEEL) } } ``` -------------------------------- ### Duplicate Anonymous Queries Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/graphql-validations-migration-guide.mdx Example of two anonymous queries that would conflict and their solutions. ```graphql # This will fail if executed together in # a single operation with the following two queries: query { someField } query { otherField } ``` ```graphql query { someField otherField } ``` ```graphql query FirstQuery { someField } query SecondQuery { otherField } ``` -------------------------------- ### Install prerequisites for Graph Node Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/indexing/overview.mdx Additional packages required for running Graph Node on Ubuntu. ```sh sudo apt-get install -y clang libpg-dev libssl-dev pkg-config ``` -------------------------------- ### Build Artifact Output Example Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/querying/graph-client/README.md Example output from the 'graphclient build' command, showing the artifact generation process. ```sh GraphClient: Cleaning existing artifacts GraphClient: Reading the configuration 🕸️: Generating the unified schema 🕸️: Generating artifacts 🕸️: Generating index file in TypeScript 🕸️: Writing index.ts for ESM to the disk. 🕸️: Cleanup 🕸️: Done! => .graphclient ``` -------------------------------- ### Logging Levels Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/indexing/tap.mdx Examples of setting the RUST_LOG environment variable for different logging verbosity levels in indexer-service-rs. ```bash # Recommended for production export RUST_LOG=indexer_service=info,indexer_tap_agent=info # For debugging export RUST_LOG=indexer_service=debug,indexer_tap_agent=debug ``` -------------------------------- ### Install Subgrounds Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/subgraphs/querying/python.mdx Instructions for installing the Subgrounds library using pip. ```bash pip install --upgrade subgrounds # or python -m pip install --upgrade subgrounds ``` -------------------------------- ### Casting - Safe Scenarios Source: https://github.com/graphprotocol/docs/blob/main/website/src/pages/en/resources/migration-guides/assemblyscript-migration-guide.mdx Examples of safe casting using the 'as' keyword or angle brackets in AssemblyScript. ```typescript let byteArray = new ByteArray(10) let uint8Array = byteArray as Uint8Array // equivalent to: byteArray ``` ```typescript // primitive casting let a: usize = 10 let b: isize = 5 let c: usize = a + (b as usize) ``` ```typescript // upcasting on class inheritance class Bytes extends Uint8Array {} let bytes = new Bytes(2) // bytes // same as: bytes as Uint8Array ```