/substreams-evm:substreams-devfrom substreams-evm
Expert knowledge for developing, building, and debugging Substreams projects on any blockchain. Covers manifests, Rust modules, protobuf schemas, and CLI workflows.
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 building Substreams projects - high-performance blockchain data indexing and transformation.
Substreams is a powerful blockchain indexing technology that enables:
substreams.yaml): Defines modules, networks, dependenciesmy-substreams/
├── substreams.yaml # Manifest
├── proto/
│ └── events.proto # Schema definitions
├── src/
│ └── lib.rs # Rust module code
├── Cargo.toml # Rust dependencies
└── build/ # Generated files (gitignored)
substreams build for protobuf code generationRunning substreams run against hosted endpoints requires authentication:
substreams auth # Interactive authentication
# Or set SUBSTREAMS_API_TOKEN environment variable
substreams init or create manifest manually.proto files for your data structuressrc/lib.rssubstreams build to compile to .spkgsubstreams run with small block range (recommended: 1000 blocks)Map Module - Transforms input to output
- name: map_events
kind: map
inputs:
- source: sf.ethereum.type.v2.Block
output:
type: proto:my.types.Events
Store Module - Aggregates data across blocks
- name: store_totals
kind: store
updatePolicy: add
valueType: int64
inputs:
- map: map_events
Index Module - Filters blocks for efficient querying
- name: index_transfers
kind: index
inputs:
- map: map_events
output:
type: proto:sf.substreams.index.v1.Keys
When modules produce unexpected results:
substreams graph to visualize dependenciesinitialBlock is set appropriately--production-modeSee references/manifest-spec.md for complete specification.
Package metadata:
specVersion: v0.1.0
package:
name: my-substreams
version: v1.0.0
description: Description of what this substreams does
Protobuf imports:
protobuf:
files:
- events.proto
importPaths:
- ./proto
Binary reference (WASM code):
binaries:
default:
type: wasm/rust-v1
file: ./target/wasm32-unknown-unknown/release/my_substreams.wasm
Network configuration:
network: mainnet
Supported networks: See references/networks.md
use substreams::errors::Error;
use substreams::prelude::*;
use substreams_ethereum::pb::eth::v2::Block;
#[substreams::handlers::map]
pub fn map_events(block: Block) -> Result<Events, Error> {
let mut events = Events::default();
for trx in block.transactions() {
for (log, _call) in trx.logs_with_calls() {
// Process logs, extract events
if is_transfer_event(log) {
events.transfers.push(extract_transfer(log));
}
}
}
Ok(events)
}
#[substreams::handlers::store]
pub fn store_totals(events: Events, store: StoreAddInt64) {
for transfer in events.transfers {
store.add(0, &transfer.token, transfer.amount as i64);
}
}
Result<T, Error> returnssubstreams-ethereum cratesubstreams run before deployingCRITICAL: One of the greatest performance impacts in Substreams is excessive cloning of data structures.
Cloning large data structures is expensive:
Use Rust's ownership system to transfer or borrow data instead of cloning.
#[substreams::handlers::map]
pub fn map_events(block: Block) -> Result<Events, Error> {
let mut events = Events::default();
for trx in block.transactions() {
// ❌ BAD: Cloning entire transaction
let transaction = trx.clone();
for (log, _call) in transaction.logs_with_calls() {
// ❌ BAD: Cloning log
let log_copy = log.clone();
if is_transfer_event(&log_copy) {
events.transfers.push(extract_transfer(&log_copy));
}
}
}
Ok(events)
}
#[substreams::handlers::map]
pub fn map_events(block: Block) -> Result<Events, Error> {
let mut events = Events::default();
// ✅ GOOD: Iterate by reference
for trx in block.transactions() {
// ✅ GOOD: Borrow, don't clone
for (log, _call) in trx.logs_with_calls() {
if is_transfer_event(log) {
// ✅ GOOD: Only extract what you need
events.transfers.push(extract_transfer(log));
}
}
}
Ok(events)
}
fn is_transfer_event(log: &Log) -> bool {
// Use reference, no cloning
!log.topics.is_empty() &&
log.topics[0] == TRANSFER_EVENT_SIGNATURE
}
fn extract_transfer(log: &Log) -> Transfer {
// Extract only the fields you need
Transfer {
from: Hex::encode(&log.topics[1]),
to: Hex::encode(&log.topics[2]),
amount: Hex::encode(&log.data),
// Don't copy the entire log
}
}
Clone only small, necessary data:
// ✅ OK: Cloning small strings
let token_address = Hex::encode(&log.address).clone();
// ✅ OK: Cloning primitive types
let block_number = block.number.clone();
// ❌ BAD: Cloning entire structures
let block_copy = block.clone(); // Never do this!
let trx_copy = transaction.clone(); // Avoid this!
Use logs_with_calls(): Iterate logs without cloning
for (log, _call) in trx.logs_with_calls() { } // Good
for log in trx.receipt.as_ref().unwrap().logs.clone() { } // Bad
Use references when appropriate: Pass references to avoid unnecessary cloning
fn process_log(log: &Log) { } // Good for read-only access
fn process_log(log: Log) { } // Good when consuming/transforming data
Extract minimal data: Only copy what you actually need
// Good: Extract only needed fields
let amount = parse_amount(&log.data);
// Bad: Copy entire log just to get one field
let log_copy = log.clone();
let amount = parse_amount(&log_copy.data);
Use into() for consumption: When you need to consume data
// When you truly need to take ownership
events.transfers.push(Transfer {
from: topics[1].into(), // Consumes the data
to: topics[2].into(),
});
Pitfall #1: Cloning in filters
// ❌ BAD
block.transactions()
.iter()
.filter(|trx| trx.clone().to == target) // Clone every transaction!
// ✅ GOOD
block.transactions()
.iter()
.filter(|trx| trx.to == target) // Just compare
Pitfall #2: Unnecessary defensive copies
// ❌ BAD
let block_copy = block.clone();
for trx in block_copy.transactions() { } // Why clone the whole block?
// ✅ GOOD
for trx in block.transactions() { } // Use the block directly
Pitfall #3: Cloning for mutation
// ❌ BAD
let mut trx_copy = trx.clone();
trx_copy.value = process(trx_copy.value); // Clone just to mutate
// ✅ GOOD
let new_value = process(&trx.value); // Process reference, create new value
Use substreams run with timing to measure performance:
# Test with cloning (slow)
time substreams run -s 17000000 -t +1000 map_events
# Test without cloning (fast)
time substreams run -s 17000000 -t +1000 map_events
# You should see significant speedup (2-10x) by avoiding clones
substreams run to identify bottlenecksSee references/patterns.md for detailed examples:
To get the current head block of a chain (useful for determining the latest block number):
Using Substreams:
# Quick head block lookup for a network
substreams run common@latest -s -1 --network mainnet
# Or with explicit endpoint
substreams run common@latest -e=<network-id-alias-or-host> -s -1 -o jsonl
Read the first line of output to get the head block information. The -s -1 flag starts from the latest block.
Using firecore:
# JSON output (use jq for further processing if available)
firecore tools firehose-client <network-id-alias-or-host> -o json -- -1
# Text output (less detail), first line looks like:
# Block #24327807 (14b58bd3fa091c05a46d084bba1e78090d52556d29f4312da77b7aa3220423f4)
firecore tools firehose-client <network-id-alias-or-host> -o text -- -1
Read the first line of output to get the head block information.
substreams gui for visual debugging (when available).spkg files for reproducibilitydoc: fields in manifest for clarityBuild fails:
rustup target add wasm32-unknown-unknownbuf CLI is installed (required for proto generation)protobuf.excludePaths with sf/substreams and google when importing spkgsEmpty output:
initialBlock is before first relevant blockPerformance issues:
--production-mode for large rangesWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub pinax-network/substreams-evm --plugin substreams-evm6 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-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-sinkExpert knowledge for consuming Substreams data in applications. Use when building sinks, real-time data pipelines, or integrating Substreams outputs into Go, JavaScript, Python, or Rust applications./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.