/substreams-evm:substreams-sinkfrom substreams-evm
Expert knowledge for consuming Substreams blockchain data in applications. Covers building production-grade sinks and real-time data pipelines with cursor persistence and reorg handling.
Ships in substreams-evm. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Expert assistant for consuming Substreams data - building production-grade sinks and data pipelines.
A Substreams sink is an application that:
Note: Before building a custom sink, consider using existing solutions:
- substreams-sink-sql - For PostgreSQL and ClickHouse. Handles cursor management, reorgs, batching, and schema management out of the box.
- substreams-sink-kv - For key-value stores.
- substreams-sink-files - For file-based outputs (JSON, CSV, Parquet).
The examples in this guide use database code for illustration purposes. For production SQL database sinks,
substreams-sink-sqlis highly recommended as it solves cursor persistence, reorg handling, batching, and many edge cases already.
mainnet.eth.streamingfast.io:443)All Substreams endpoints require authentication:
# Set API key (recommended for CLI tools)
export SUBSTREAMS_API_KEY="your-api-key"
# Or set bearer token directly
export SUBSTREAMS_API_TOKEN="your-jwt-token"
Get your API key from thegraph.market or pinax.network.
For most use cases, use substreams-sink-sql with the pre-built EVM SPKGs:
use substreams_stream::{BlockResponse, SubstreamsStream};
let stream = SubstreamsStream::new(
endpoint,
cursor,
package,
modules.clone(),
"map_events".to_string(),
start_block,
stop_block,
);
while let Some(response) = stream.next().await {
match response? {
BlockResponse::New(data) => {
// Process block data
persist_cursor(&data.cursor);
}
BlockResponse::Undo(signal) => {
// Handle reorg
rewind_to_block(signal.last_valid_block);
persist_cursor(&signal.last_valid_cursor);
}
}
}
See references/rust-sink.md for complete guide.
The cursor is the most critical piece of sink development.
RULE #1: Persist cursor AFTER successful processing, never before.
RULE #2: On restart, load persisted cursor and resume from there.
RULE #3: Blank/empty cursor means start from the beginning.
The cursor is an opaque string that encodes:
Cursor persistence patterns:
| Storage | Use Case | Example |
|---|---|---|
| File | Development, single instance | cursor.txt |
| Database | Production, multi-instance | Cursors table with module key |
| Redis | High availability | Key-value with TTL |
See references/cursor-reorg.md for detailed patterns.
When a chain reorganizes, you receive a BlockUndoSignal:
BlockUndoSignal {
last_valid_block: BlockRef { num: 17000100, id: "0xabc..." }
last_valid_cursor: "opaque-cursor-string"
}
Required actions:
last_valid_block.numlast_valid_cursorFinal blocks only mode (recommended for most sinks):
final_blocks_only: true in requestFatal errors (do not retry):
Unauthenticated - Invalid or expired tokenInvalidArgument - Bad request parametersInternal - Server-side bugRetryable errors (implement exponential backoff):
Unavailable - Server temporarily unavailableResourceExhausted - Rate limitedExponential backoff pattern:
Base delay: 500ms
Max delay: 45-90 seconds
Jitter: Add random 0-100ms
| Feature | Production Mode | Development Mode |
|---|---|---|
| Parallel execution | Yes | No |
| Output | Single module only | All modules |
| Performance | Optimized | Debug-friendly |
| Use case | Sinks | Testing, debugging |
Always use production mode for sinks:
sink.WithProductionMode() // Go
production_mode=True // Python
productionMode: true // JavaScript
| Network | Endpoint |
|---|---|
| Ethereum Mainnet | mainnet.eth.streamingfast.io:443 |
| Ethereum Sepolia | sepolia.eth.streamingfast.io:443 |
| Polygon | polygon.streamingfast.io:443 |
| Arbitrum One | arb-one.streamingfast.io:443 |
| Optimism | optimism.streamingfast.io:443 |
| Base | base.streamingfast.io:443 |
| BSC | bsc.streamingfast.io:443 |
| Solana | mainnet.sol.streamingfast.io:443 |
| Near | mainnet.near.streamingfast.io:443 |
Full list: thegraph.market/supported-networks
# Explicit range
--start-block 17000000 --stop-block 17001000
# From manifest initialBlock
--start-block : --stop-block 17001000
# Relative stop (process 1000 blocks)
--start-block 17000000 --stop-block +1000
# To chain head (live streaming)
--start-block 17000000 --stop-block 0
Pass runtime parameters to modules:
# Single parameter
-p "map_events=0xa0b86a33e6..."
# Multiple parameters
-p "map_events=0xa0b86a33..." -p "filter_module=type:transfer"
# JSON parameters
-p 'map_events={"contracts":["0x123","0x456"],"min_value":1000}'
Generate language bindings from .spkg files:
# Install buf
go install github.com/bufbuild/buf/cmd/buf@latest
# Generate from local .spkg
buf generate --exclude-path="google" ./my-substreams.spkg#format=bin
# Generate from URL
buf generate "https://spkg.io/streamingfast/substreams-eth-block-meta-v0.4.3.spkg#format=binpb"
# Generate from buf registry
buf generate buf.build/streamingfast/substreams --include-imports
"Unauthenticated" error:
"Connection refused" error:
No data received:
initialBlock in manifest is before your start blockSlow processing:
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
6 skills in this plugin
/release-conventionsNaming conventions for tags, releases, and SPKGs in the substreams-evm monorepo. Use when creating releases, tagging versions, or publishing packages./substreams-devExpert knowledge for developing, building, and debugging Substreams projects on any blockchain. Use when working with substreams.yaml manifests, Rust modules, protobuf schemas, or blockchain data processing./substreams-packInstructions for building, packing, and distributing Substreams packages (.spkg) in the substreams-evm monorepo. Use when building crates, running `substreams pack`, or copying .spkg files./substreams-sqlExpert knowledge for building SQL database sinks from Substreams. Covers database changes (CDC), relational mappings, PostgreSQL, ClickHouse, and materialized views./substreams-testingExpert knowledge for testing Substreams applications. Covers unit testing, integration testing, performance testing, and FireCode tools usage.npx claudepluginhub pinax-network/substreams-evm --plugin substreams-evm