🚀Deploy a subgraph using the 0xgraph CLI
This document provides a quick start guide for deploying a subgraph using the Command Line Interface (CLI).
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
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://app.0xgraph.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 0xgraph 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 0xgraph build
command, for detail please use --help
argument:
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
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 0xgraph hosted 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 0xgraph 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.
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 0xgraph remove
command, for detail please use --help
argument:
Last updated