This document provides a quick start guide for deploying a subgraph using the Command Line Interface (CLI).
Last updated
Summary: The 0xgraph CLI is an essential tool enabling developers to seamlessly create, deploy, and manage subgraphs - providing streamlined blockchain data querying and indexing. It gives you the superuser access to our enterprise-grade subgraph infrastructure.
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:
Get started by install the 0xgraph cli
npmi@xgraph/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 0xgraph build command, for detail please use --help argument:
$0xgraphbuild--helpBuildsasubgraphand (optionally) uploads it to IPFS.USAGE$0xgraphbuild [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 0xgraph's hosted 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
0xgraphcreate<my-subgraph-name>
Success output:
Createdsubgraph:<my-subgraph-name>
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 0xgraph hosted service:
0xgraphdeploy
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>
Your deployed subgraphs can be accessed and viewed through the web-based UI.
Delete your deployed subgraphs
To remove/delete your deployed subgraph, you may use the following command with your subgraph name.
0xgraphremove<my-subgraph-name>
Success output:
Removedsubgraph:<my-subgraph-name>
You may also pass in parameter for 0xgraph remove command, for detail please use --help argument:
Unregisters a subgraph name
USAGE
$ 0xgraph 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