🚀Deploy a subgraph using the Graph CLI
This document provides a quick start guide for deploying a subgraph using the Command Line Interface (CLI).
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:
For Mantle Goerli Testnet:
For Mantle Sepolia Testnet:
Get started by install the Graph cli
Authentication with API key
Log in with the API key created earlier, and enter the API key when prompted:
Enter your deploy key when promoted
You can sign up for a deployment API key by visiting https://subgraph.mantle.xyz/dashboard/api
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. 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 likestartBlock
anddescription
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.
Subgraph compilation
1. Generate types and mappings for your subgraph
The codegen step generate the necessary code files that will handle indexing and querying data according to your schema and mappings.
Running the following command in your subgraph project root will create types and mappings for your subgraph.
Success output:
You may also pass in parameter for graph codegen
command, for detail please use --help
argument:
2. Build your subgraph
After generating your subgraph types and mappings, you may proceed by executing the subsequent command to build your subgraph:
Success output:
You may also pass in parameter for graph build
command, for detail please use --help
argument:
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
Success output:
2. Deploy your subgraph 🚀
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>
Success output:
You may also pass in parameter for graph create
command, for detail please use --help
argument:
View your deployed subgraphs
Web UI
Your deployed subgraphs can be accessed and viewed through the web-based UI.
CLI
Your deployed subgraphs can also be accessed via the following command.
Delete your deployed subgraphs
To remove/delete your deployed subgraph, you may use the following command with your subgraph name.
Success output:
You may also pass in parameter for graph remove
command, for detail please use --help
argument:
Last updated