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

> [!NOTE]
>
> 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 i @graphprotocol/graph-cli `

> [card] [NPM CLI Package](https://www.npmjs.com/package/@graphprotocol/graph-cli)
>
> Install the graph npm package

## Generate API Key

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

> [!NOTE]
>
> 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:

> [card] 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`.

&#x20;

> [card] 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.

> [card] Mappings File
>
> 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.

> [!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.

***

## Subgraph Compilation

**1. Generate Types and Mappings**

> [!NOTE]
>
> The codegen step generates code files for indexing and querying data based on your schema and mappings.

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] Codegen Options
>
> > [!NOTE]
> >
> > View all options with `graph codegen --help`:
>
> ```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.
> ```

**2. 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] Build Options
>
> > [!NOTE]
> >
> > View all options with `graph build --help`:
>
> ```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.
> ```

**3. Deploy your Subgraph**

Then deploy your Subgraph:

```bash theme={null}
graph deploy <your_subgraph> --node
https://dolomiteapi.0xgraph.xyz/deploy
--ipfs https://dolomiteapi.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
```

> [card] View Your Subgraphs
>
> Access your deployed Subgraphs through the web-based UI at [dolomite.0xgraph.xyz](http://dolomite.0xgraph.xyz)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.