Substreams
Reading time: 2 min
Substreams is a powerful blockchain indexing technology developed for The Graph Network. It enables developers to write Rust modules, compose data streams alongside the community, and provide extremely high-performance indexing due to parallelization in a streaming-first approach.
With Substreams, developers can quickly extract data from different blockchains (Ethereum, BNB, Solana, ect.) and send it to various locations of their choice, such as a Postgres database, a Mongo database, or a Subgraph. Additionally, Substreams packages enable developers to specify which data they want to extract from the blockchain.
- You write a Rust program, which defines the transformations that you want to apply to the blockchain data. For example, the following Rust function extracts relevant information from an Ethereum block (number, hash, and parent hash).
fn get_my_block(blk: Block) -> Result<MyBlock, substreams::errors::Error> {let header = blk.header.as_ref().unwrap();Ok(MyBlock {number: blk.number,hash: Hex::encode(&blk.hash),parent_hash: Hex::encode(&header.parent_hash),})}
You wrap up your Rust program into a WASM module just by running a single CLI command.
The WASM container is sent to a Substreams endpoint for execution. The Substreams provider feeds the WASM container with the blockchain data and the transformations are applied.
You select a , a place where you want to send the transformed data (a Postgres database or a Subgraph, for example).
The official Substreams documentation is currently maintained by the StreamingFast team .
To learn about the latest version of Substreams CLI, which enables developers to bootstrap a Substreams project without any code, please check .