The Graph CLI is an essential tool enabling developers to seamlessly create, deploy, and manage subgraphs—providing streamlined blockchain data querying and indexing. It gives you superuser access to our enterprise-grade subgraph infrastructure. Additionally, we are fully compatible with The Graph’s tooling, and the CLI works seamlessly out of the box with our platform.

Deployment Network Definitions

For developers who are already familiar with Graph Protocol tooling, below are the network definitions to deploy subgraphs on 0xgraph. These settings can be configured in the subgraph.yaml file:

Installation

1

Install CLI Package

NPM CLI Package

Install the graph npm package

Generate API Key

Create an API key: Visit 0xgraph Dashboard to generate your API key. For a comprehensive tutorial on generating API keys, visit the Account Creation Page.

You need to specify the 0xgraph deployment endpoint. Your API key should only be used for the 0xgraph deployment endpoint.


Create your own Subgraph

Details regarding creating your own Subgraph is beyond the scope of this documentation. The Graph’s official documentation provides detailed guides and examples for each step of the Subgraph creation process. It also covers advanced topics such as indexing strategies, filtering, and pagination. We recommend referring to their documentation for a comprehensive reference on Subgraph development with The Graph.

Core Components

A typical Subgraph project has the following components:

Manifest File

The subgraph.yaml manifest file serves as the root configuration, containing smart contract references, entity mappings, handler functions, and deployment parameters like startBlock and description.

Schema File

The schema.graphql file defines all the entities and their relationships for your Subgraph’s GraphQL API, determining what blockchain data will be indexed and made queryable.

Mappings File

Written in AssemblyScript, a TypeScript-like language specifically designed for WebAssembly, the mappings file transforms raw blockchain data into structured entities that match your GraphQL schema through a set of data handling functions.

Messari maintains a well-curated GitHub repository that offers a comprehensive collection of example Subgraphs, which serves as a valuable resource for those seeking to start their subgraph development journey.


Subgraph Compilation

1

Generate Types and Mappings

The codegen step generates code files for indexing and querying data based on your schema and mappings.

Run in your project root:

graph codegen

Success output:

    Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
    Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
    Skip migration: Bump mapping apiVersion from 0.0.3 to 0.0.4
    Skip migration: Bump mapping apiVersion from 0.0.4 to 0.0.5
    Skip migration: Bump mapping apiVersion from 0.0.5 to 0.0.6
    Skip migration: Bump manifest specVersion from 0.0.1 to 0.0.2
    Skip migration: Bump manifest specVersion from 0.0.2 to 0.0.4
  ✔ Apply migrations
  ✔ Load subgraph from subgraph.yaml
    Load contract ABI from abis/factory.json
    Load contract ABI from abis/ERC20.json
    Load contract ABI from abis/ERC20SymbolBytes.json
    Load contract ABI from abis/ERC20NameBytes.json
  ✔ Load contract ABIs
    Generate types for contract ABI: Factory (abis/factory.json)
    Generate types for contract ABI: ERC20 (abis/ERC20.json)
    Generate types for contract ABI: ERC20SymbolBytes (abis/ERC20SymbolBytes.json)
    Generate types for contract ABI: ERC20NameBytes (abis/ERC20NameBytes.json)
    Write types to generated/Factory/Factory.ts
    Write types to generated/Factory/ERC20.ts
    Write types to generated/Factory/ERC20SymbolBytes.ts
    Write types to generated/Factory/ERC20NameBytes.ts
  ✔ Generate types for contract ABIs
    Generate types for data source template Pair
    Write types for templates to generated/templates.ts
  ✔ Generate types for data source templates
    Load data source template ABI from abis/pair.json
    Load data source template ABI from abis/factory.json
  ✔ Load data source template ABIs
    Generate types for data source template ABI: Pair > Pair (abis/pair.json)
    Generate types for data source template ABI: Pair > Factory (abis/factory.json)
    Write types to generated/templates/Pair/Pair.ts
    Write types to generated/templates/Pair/Factory.ts
  ✔ Generate types for data source template ABIs
  ✔ Load GraphQL schema from schema.graphql
    Write types to generated/schema.ts
  ✔ Generate types for GraphQL schema

  Types generated successfully
2

Build Your Subgraph

After generating types, build your subgraph:

graph build

Success Output:

  Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
  Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
  Skip migration: Bump mapping apiVersion from 0.0.3 to 0.0.4
  Skip migration: Bump mapping apiVersion from 0.0.4 to 0.0.5
  Skip migration: Bump mapping apiVersion from 0.0.5 to 0.0.6
  Skip migration: Bump manifest specVersion from 0.0.1 to 0.0.2
  Skip migration: Bump manifest specVersion from 0.0.2 to 0.0.4
✔ Apply migrations
✔ Load subgraph from subgraph.yaml
  Compile data source: Factory => build/Factory/Factory.wasm
  Compile data source template: Pair => build/templates/Pair/Pair.wasm
✔ Compile subgraph
  Copy schema file build/schema.graphql
  Write subgraph file build/Factory/factory.json
  Write subgraph file build/Factory/ERC20.json
  Write subgraph file build/Factory/ERC20SymbolBytes.json
  Write subgraph file build/Factory/ERC20NameBytes.json
  Write subgraph file build/Pair/pair.json
  Write subgraph file build/Pair/factory.json
  Write subgraph manifest build/subgraph.yaml
✔ Write compiled subgraph to build/

Build completed: build/subgraph.yaml
3

Deploy your Subgraph

Then deploy your Subgraph:

graph deploy <your_subgraph> --node
https://apeapi.0xgraph.xyz/deploy
--ipfs https://apeapi.0xgraph.xyz/ipfs
--deploy-key <your_API_key>

Success output:

  Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
  Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
  Skip migration: Bump mapping apiVersion from 0.0.3 to 0.0.4
  Skip migration: Bump mapping apiVersion from 0.0.4 to 0.0.5
  Skip migration: Bump mapping apiVersion from 0.0.5 to 0.0.6
  Skip migration: Bump manifest specVersion from 0.0.1 to 0.0.2
  Skip migration: Bump manifest specVersion from 0.0.2 to 0.0.4
✔ Apply migrations
✔ Load subgraph from subgraph.yaml
  Compile data source: Factory => build/Factory/Factory.wasm
  Compile data source template: Pair => build/templates/Pair/Pair.wasm
✔ Compile subgraph
  Copy schema file build/schema.graphql
  Write subgraph file build/Factory/factory.json
  Write subgraph file build/Factory/ERC20.json
  Write subgraph file build/Factory/ERC20SymbolBytes.json
  Write subgraph file build/Factory/ERC20NameBytes.json
  Write subgraph file build/Pair/pair.json
  Write subgraph file build/Pair/factory.json
  Write subgraph manifest build/subgraph.yaml
✔ Write compiled subgraph to build/
  Add file to IPFS build/schema.graphql
                .. Qmckrwbgbx3FjsVH4AU8xP3zgdg3rPnzNo7pmApAmhQkA4
  Add file to IPFS build/Factory/factory.json
                .. QmZ55G1yYFzde8Vcq4cpLfNgPSEibpLi9aYCqS1jEvCKQ9
  Add file to IPFS build/Factory/ERC20.json
                .. QmPfKNZPkVATzL3EHypkcsyKhehR4jkiYEVqSzh2hxWYj1
  Add file to IPFS build/Factory/ERC20SymbolBytes.json
                .. QmbHnhUFZa6qqqRyubUYhXntox1TCBxqryaBM1iNGqVJzT
  Add file to IPFS build/Factory/ERC20NameBytes.json
                .. QmQCP6Pdp1MqpwRv2qoPHuUTwZGy7Q3eDHg4w5kzwE9mBj
  Add file to IPFS build/Factory/Factory.wasm
                .. QmNksN9HGSyMfc4XrjQeHuDKsBQk1xHEKVE2dLwHQQu4kb
  Add file to IPFS build/Pair/pair.json
                .. QmbPLMADBP8L6LBVP3ZBQ8RgG7ghamD8DvbdUxHAjZrLgm
  Add file to IPFS build/Pair/factory.json
                .. QmZ55G1yYFzde8Vcq4cpLfNgPSEibpLi9aYCqS1jEvCKQ9 (already uploaded)
  Add file to IPFS build/templates/Pair/Pair.wasm
                .. QmSZSUoNinhNshD26iwKyzut6s3w5Lmec3P9szBovfQg8V
✔ Upload subgraph to IPFS

Build completed: QmdXJQUxgrzP8pVotTqiwirJ6NxfmdNdQ6rWQv2rmJpBQp

Deployed to /api/public/1b347b54-0d7f-4008-9a62-60fdcaffec9c/subgraphs/v2-subgraph/v0.89.0/gn

Subgraph endpoints:
Queries (HTTP):     /api/public/1b347b54-0d7f-4008-9a62-60fdcaffec9c/subgraphs/v2-subgraph/v0.89.0/gn

View Your Subgraphs

Access your deployed Subgraphs through the web-based UI at apechain.0xgraph.xyz