Substreams Tutorial — Understanding Substreams
Here is a quick example to explore what Substreams are, what the role of a Substreams provider is, and how simple it can be to write your first Substreams package.
Transcript:
Extracting data from blockchain is hard, but extracting data from blockchain in a fast and reliable way is even harder. Substreams allows you to retrieve data from your favourite blockchain ultra-fast!
First of all, there is a Substreams provider. The Substreams provider takes care of storing blockchain data and making it available in a fast and reliable way.
In order for the Substreams provider to know which specific data you want to retrieve, you write a Rust program that defines the transformations that you want to apply to the blockchain data.
For example, let’s explore the following Substreams Rust program.
The function extracts a list of transactions belonging to the USDT smart contract.
The function receives a raw Ethereum block as a parameter and returns a custom object with the extracted data.First, it iterates over all the transactions of the block. Then, keeps only USDT transactions by applying a filter. And lastly, creates a custom object called “MyTransaction”, containing basic information from the transaction, such as “hash”, “from” or “to”.
Once you are done with the coding part, you can pack your Rust program into a Substreams package. Then, you can send the Substreams package to the Substreams provider for execution. The Substreams provider will start streaming data back to you ultra-fast!Optionally, you can also send the extracted data to one of the sink integrations for further processing. Among the supported integrations you can find SQL, MongoDB, or Prometheus.