> ## Documentation Index
> Fetch the complete documentation index at: https://ormilabs.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy a Subgraph with the Graph Cli

> Quick start guide for deploying a Subgraph using the Command Line Interface (CLI).

<Info>
  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.
</Info>

## 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

<Steps>
  <Step title="Install CLI Package">
    <CodeGroup>`npm i @graphprotocol/graph-cli `</CodeGroup>
  </Step>
</Steps>

<Card title="NPM CLI Package" icon="npm" href="https://www.npmjs.com/package/@graphprotocol/graph-cli" target="_blank">
  Install the graph npm package
</Card>

## Generate API Key

Create an API key: Visit [0xGraph Dashboard](https://telos.0xgraph.xyz/dashboard/api) to generate your API key. For a comprehensive tutorial on generating API keys, visit the [Account Creation Page](/dedicated-env/telos/subgraphs/getting-started/account-creation).

<Info>
  You need to specify the 0xGraph deployment endpoint. Your API key should only
  be used for the 0xGraph deployment endpoint.
</Info>

***

## 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:

<CardGroup cols={2}>
  <Card title="Manifest File" icon="file-lines">
    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`.
  </Card>

  {' '}

  <Card title="Schema File" icon="database">
    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.
  </Card>

  <Card title="Mappings File" icon="code">
    Written in [AssemblyScript](https://www.assemblyscript.org/), 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.
  </Card>
</CardGroup>

<Note>
  Messari maintains a [well-curated GitHub
  repository](https://github.com/messari/subgraphs) that offers a comprehensive
  collection of example Subgraphs, which serves as a valuable resource for those
  seeking to start their subgraph development journey.
</Note>

***

## Subgraph Compilation

<Steps>
  <Step title="Generate Types and Mappings">
    <Note>
      The codegen step generates code files for indexing and querying data based on your schema and mappings.
    </Note>

    Run in your project root:

    ```bash theme={null}
    graph codegen
    ```

    Success output:

    ```bash theme={null}
        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
    ```

    <Accordion title="Codegen Options">
      <Info>
        View all options with `graph codegen --help`:
      </Info>

      ```bash theme={null}
      USAGE
        $ graph codegen [SUBGRAPH-MANIFEST] [-h] [-o <value>] [--skip-migrations] [-w] [--uncrashable-config <value> -u]

      FLAGS
        -h, --help                    Show CLI help.
        -o, --output-dir=<value>      [default: generated/] Output directory for generated types.
        -u, --uncrashable             Generate Float S
                                      subgraph Uncrashable helper file.
        -w, --watch                   Regenerate types when subgraph files change.
        --skip-migrations             Skip subgraph migrations.
        --uncrashable-config=<value>  Directory for uncrashable config.
      ```
    </Accordion>
  </Step>

  <Step title="Build Your Subgraph">
    After generating types, build your subgraph:

    ```bash theme={null}
    graph build
    ```

    Success Output:

    ```bash theme={null}
      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
    ```

    <Accordion title="Build Options">
      <Info>
        View all options with `graph build --help`:
      </Info>

      ```bash theme={null}
      Builds a subgraph and (optionally) uploads it to IPFS.

        USAGE
          $ graph build [SUBGRAPH-MANIFEST] [-h] [-i <value>] [-o <value>] [-t wasm|wast]
            [--skip-migrations] [-w] [--network <value>] [--network-file <value>]

        FLAGS
          -h, --help                    Show CLI help.
          -i, --ipfs=<value>            Upload build results to an IPFS node.
          -o, --output-dir=<value>      [default: build/] Output directory for build results.
          -t, --output-format=<option>  [default: wasm] Output format for mappings.
                                        <options: wasm|wast>
          -w, --watch                   Regenerate types when subgraph files change.
          --network=<value>             Network configuration to use from the networks config file.
          --network-file=<value>        [default: networks.json] Networks config file path.
          --skip-migrations             Skip subgraph migrations.

      DESCRIPTION
      Builds a subgraph and (optionally) uploads it to IPFS.

      ```
    </Accordion>
  </Step>

  <Step title="Deploy your Subgraph">
    Then deploy your Subgraph:

    ```bash theme={null}
    graph deploy <your_subgraph> --node
    https://telosapi.0xgraph.xyz/deploy
    --ipfs https://telosapi.0xgraph.xyz/ipfs
    --deploy-key <your_API_key>
    ```

    Success output:

    ```bash theme={null}
      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
    ```
  </Step>
</Steps>

<Card title="View Your Subgraphs" icon="browser">
  Access your deployed Subgraphs through the web-based UI at [telos.0xgraph.xyz](http://telos.0xgraph.xyz)
</Card>

```
```
