This document provides a quick start guide for deploying a subgraph using the Command Line Interface (CLI).
Last updated
This quick start guide outlines streamlined instructions for deploying subgraphs using the Command Line Interface (CLI). Developers looking to swiftly incorporate subgraph capabilities into their projects will find straightforward guidance and pro tips for getting set up fast.
Summary: The Graph CLI is an essential tool enabling developers to seamlessly create, deploy, and manage subgraphs - providing streamlined blockchain data querying and indexing.
Deployment Network definitions
For developers who are already familiar with Graph Protocol tooling, below are the network definitions to deploy subgraphs on Mantle. These settings can be configured in the subgraph.yaml file:
For Mantle Mainnet:
network:'mantle'
For Mantle Sepolia Testnet:
network:'mantle-sepolia'
Get started by install the Graph cli
npmi@graphprotocol/graph-cli
Authentication with API key
Log in with the API key created earlier, and enter the API key when prompted:
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.
A typical subgraph project have the following components:
The manifest file. The subgraph.yaml at the root defines all the major parameters of a subgraph project. It contains a list of all the smart contracts being indexed, as well as a list of entities and their corresponding handler functions. We will be adding more properties like startBlock and description to the YAML file in the tutorial. You can read about all the specifications in detail in the Graph docs.
The schema file. At its core, a subgraph is a GraphQL API that indexes data from the blockchain.
The schema.graphql file at the root of our project contains all our entities. These entities define what data our subgraph indexes.
Here is what an entity could look like:
The mappings file. A mappings file contains functions that take the data from a blockchain, and convert it into manageable data along the lines of our GraphQL entities. It is written in AssemblyScript, which is a TypeScript-like language with a stricter syntax.
This file contains the logic that dictates how data should be retrieved and stored when someone interacts with the smart contracts we intend to index.
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.
You may also pass in parameter for graph build command, for detail please use --help argument:
$graphbuild--helpBuildsasubgraphand (optionally) uploads it to IPFS.USAGE$graphbuild [SUBGRAPH-MANIFEST] [-h] [-i <value>] [-o <value>] [-t wasm|wast] [--skip-migrations] [-w] [--network <value>] [--network-file <value>]FLAGS-h,--helpShowCLIhelp.-i,--ipfs=<value>UploadbuildresultstoanIPFSnode.-o,--output-dir=<value> [default: build/]Outputdirectoryforbuildresults.-t,--output-format=<option> [default: wasm]Outputformatformappings.<options:wasm|wast>-w,--watchRegeneratetypeswhensubgraphfileschange. --network=<value>Networkconfigurationtousefromthenetworksconfigfile. --network-file=<value>[default:networks.json]Networksconfigfilepath.--skip-migrationsSkipsubgraphmigrations.DESCRIPTIONBuildsasubgraphand (optionally) uploads it to IPFS.
Subgraph deployment
1. Create/register your subgraph name
Before you deploy the subgraph to Mantle Subgraph Service, you need to pick a unique name for the subgraph in order to create/register the subgraph in the system by running the command below, and prompts
After creating/registering your subgraph name in the hosted service, you can run the following command to deploy the subgraph to the Mantle Subgraph Service:
The command line will give you a list of prompts regarding subgraph name and version. Note: for the subgraph name, it must match the subgraph name you registered in the above step, i.e. <my-subgraph-name>
You may also pass in parameter for graph remove command, for detail please use --help argument:
Unregisters a subgraph name
USAGE
$ graph remove SUBGRAPH-NAME [-h] [-g <value>]
FLAGS
-g, --node=<value> Graph node to delete the subgraph from.
-h, --help Show CLI help.
DESCRIPTION
Unregisters a subgraph name