This guide explains how to integrate a new blockchain network into Graph Node. Chain integration involves implementing theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/graphprotocol/graph-node/llms.txt
Use this file to discover all available pages before exploring further.
Blockchain trait and providing chain-specific adapters for data ingestion and trigger processing.
Overview
Graph Node uses a modular architecture that allows different blockchain networks to be integrated by implementing a set of core traits. Each chain integration lives in thechain/ directory and provides:
- Data source definitions
- Trigger types and filtering
- Block stream implementation
- Runtime adapters for contract calls
- Block ingestion from RPC or Firehose
Architecture
The chain integration architecture consists of several key components:- Chain Adapter: Connects to blockchain nodes and converts data
- Block Stream: Provides event-driven streaming of blocks
- Trigger Processing: Matches blockchain events to subgraph handlers
- Runtime: Executes subgraph code in WASM sandbox
- Store: Persists entities with block-level granularity
Project Structure
Each chain integration follows this structure:Core Traits
Blockchain Trait
TheBlockchain trait is the primary interface that all chains must implement:
Block Trait
Blocks must implement theBlock trait:
Implementation Steps
Extension Points
Custom Node Capabilities
Define chain-specific node capabilities:Custom Decoder Hooks
Implement decoder hooks for preprocessing data:Subgraph Manifest Schema
Define the YAML schema for your chain:Testing
Unit Tests
Write unit tests for core components:Integration Tests
Create integration tests intests/integration-tests/:
Runner Tests
Create runner tests instore/test-store/tests/chain/mychain/:
Examples
Ethereum Implementation
Seechain/ethereum/ for a full-featured reference implementation with:
- RPC and Firehose support
- Event, call, and block handlers
- Call caching
- Reorg handling
- Trace support
NEAR Implementation
Seechain/near/ for a simpler Firehose-only implementation:
- Receipt-based triggers
- No dynamic data sources
- Account filtering (exact and partial matches)
Common Patterns
Handling Reorgs
Block Caching
Configuration
Add chain configuration toconfig.toml:
Best Practices
- Error Handling: Use
Resulttypes and provide context withanyhow - Async/Await: Use
async_traitfor trait implementations - Logging: Use structured logging with
slog - Caching: Cache frequently accessed data (blocks, receipts)
- Metrics: Add Prometheus metrics for monitoring
- Testing: Write comprehensive unit and integration tests
- Documentation: Document chain-specific behavior and limitations
Performance Optimization
Batch Loading
Parallel Processing
UseFuturesOrdered for parallel processing:
Debugging
Enable Debug Logging
Common Issues
Block not found: Ensure block ingestion is running and synced Trigger mismatch: Check filter implementation and data source matching logic Reorg issues: Verifyis_on_main_chain and ancestor_block implementations

