子流

Reading time: 2 min

子流Logo

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.

子流的工作原理分为四个步骤

链到本节
  1. **您编写了一个Rust程序,定义了要应用于区块链数据的转换操作。**例如,以下的Rust函数从以太坊区块中提取相关信息(区块号、哈希和父哈希)。
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),
})
}
  1. 您只需运行一个命令行命令,就可以将您的Rust程序打包成一个WASM模块。

  2. WASM容器被发送到Substreams端点执行。 Substreams提供商将区块链数据传送给WASM容器,然后执行转换操作。

  3. You select a sink, a place where you want to send the transformed data (a Postgres database or a Subgraph, for example).

子流文档

链到本节

Substreams的官方文档目前由StreamingFast团队在StreamingFast的网站上维护。

To learn about the latest version of Substreams CLI, which enables developers to bootstrap a Substreams project without any code, please check Substreams Codegen.

开始

链到本节
  • In order to develop and deploy a Substreams, you must install the Substreams CLI.
  • Then, run your first Substreams by following the Quickstart Tutorial.

知识拓展

链到本节
编辑

上页
GraphQL验证迁移指南
下页
Introduction
编辑