Initializing a subgraph
Purpose
Creates a new Subgraph project using an example template or an existing smart contract.Use case
- Use this command when starting a new Subgraph project.
- It sets up the necessary folder structure, configuration files
subgraph.yaml
, and example code. - You can specify a contract address and network to scaffold a Subgraph tailored to a specific smart contract.
Example
Generating code from subgraph files
Purpose
Generates AssemblyScript types for smart contract ABIs and the Subgraph schema.Use case
- Use this command after making changes to your
schema.graphql
file or when adding/updating smart contract ABIs. - It creates type-safe classes that make it easier to interact with blockchain data in your mappings.
Build your subgraph
Purpose
Compiles the Subgraph to WebAssembly (WASM), preparing it for deployment.Use Case
- Run this command after completing your mappings and configuration.
- It ensures your Subgraph is ready for deployment by converting it into the WASM format required by 0xGraph.
Deploy your subgraph
Purpose
Deploys the compiled Subgraph to the 0xGraph hosting service.Use case
- After building your Subgraph, use this command to upload and activate it on 0xGraph.
- Specify the deployment target (e.g., staging or production) and the Subgraph name.
Example
Run the subgraph locally
Purpose
Runs a local test environment (e.g., using Ganache or Hardhat) to test the Subgraph with simulated blockchain data.Use Case
- Use this command when developing and testing your Subgraph locally.
- It allows you to simulate blockchain events and validate mappings.
- Ideal for testing without deploying to a live environment.
Executes unit tests
Purpose
Downloads and runs the Matchstick Rust binary to execute unit tests for a Subgraph.Use Case
- Use this command to write and run unit tests for your mappings and ensure that your Subgraph logic works correctly.
- Matchstick is a testing framework built specifically for The Graph.
Add new data source
Purpose
Adds a new data source to your Subgraph’s manifest file (subgraph.yaml) and updates relevant files such as schema.graphql, ABIs, and mappings.Use case
- Use this command when adding additional smart contracts or data sources to your Subgraph.
- It automates the process of updating your Subgraph configuration and related files.
Example
Ensure you have the latest version of The Graph CLI installed to avoid potential issues with deprecated or updated commands.