Prerequisites
Before deploying a subgraph, ensure you have:- A running Graph Node instance
- PostgreSQL database configured and accessible
- IPFS node running and accessible
- An Ethereum node or provider endpoint
- Graph CLI or GND installed
Installation
- Graph CLI
- GND (Rust)
Setting Up Graph Node
Using Docker Compose
The quickest way to get started is using Docker Compose:- Graph Node on
http://localhost:8000(GraphQL HTTP) - IPFS on
http://localhost:5001 - PostgreSQL on
localhost:5432 - Admin API on
http://localhost:8020
Running from Source
Using Existing Services
If you already have IPFS and PostgreSQL running:Creating a Subgraph
Initialize Project
Define Schema
Editschema.graphql to define your data model:
Configure Manifest
Editsubgraph.yaml to configure your data sources:
Write Mappings
Implement event handlers insrc/mapping.ts:
Building the Subgraph
Generate types and compile the subgraph:command
Generates AssemblyScript types from the GraphQL schema and contract ABIs.
command
Compiles the subgraph to WebAssembly and prepares it for deployment.
Deploying the Subgraph
Create Subgraph
First, create the subgraph on your Graph Node:Deploy
Deploy your subgraph to the Graph Node:- Uploads files to IPFS
- Creates deployment with unique ID
- Starts indexing from
startBlock - Makes subgraph available for querying
Querying the Subgraph
Once deployed, you can query your subgraph:- GraphQL Playground
- HTTP Query
- JavaScript
Navigate to
http://localhost:8000/subgraphs/name/myorg/my-subgraph to access the GraphQL playground.Managing Deployments
Check Status
Remove Subgraph
Reassign Subgraph
Move a subgraph to a different node:Environment Variables
Key environment variables for deployment:String
default:"info"
Control log levels. Options:
error, warn, info, debug, traceNumber
default:"250"
Maximum expected reorg size. Larger reorgs may cause inconsistent data.
Number
default:"500"
How often to poll Ethereum for new blocks (in milliseconds).
Number
default:"100"
The ideal amount of triggers to be processed in a batch.
Number
default:"60"
Timeout for IPFS requests in seconds.
Number
Maximum execution time for a GraphQL query in seconds. Default is unlimited.
Boolean
default:"false"
If set, the process will be killed if unresponsive.
Troubleshooting
- Connection Issues
- Sync Issues
- Deployment Failures
- Query Errors
Problem: Graph Node can’t connect to EthereumSolutions:
- Verify RPC endpoint is accessible
- Check network name matches (e.g.,
mainnetnotethereum) - Ensure provider has required capabilities (archive, traces)
- Test connection:
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' YOUR_RPC_URL
Best Practices
- Development
- Performance
- Production
- Test locally first - Always test with a local Graph Node before deploying to production
- Use version labels - Tag deployments with semantic versions for tracking
- Start small - Begin with a limited block range, then expand
- Monitor resources - Watch CPU, memory, and disk usage during indexing
- Handle errors gracefully - Use try-catch in mappings and check for null values
Next Steps
- Learn about multi-network deployments
- Review the subgraph manifest specification
- Explore advanced configuration
- Set up monitoring and metrics

