Substreams is a powerful blockchain indexing technology, developed for The Graph Network.
- Substreams enables developers to write Rust modules
- It provides extremely high-performance indexing by virtue of parallelization, in a streaming-first fashion.
- Low-cost caching and archiving of blockchain data, high throughput processing, and cursor-based reorgs handling.
- The ability to store and process blockchain data using advanced parallelization techniques, making the processed data available for various types of data stores or real-time systems.
- Half hour to learn Rust
- Learn Rust With Entirely Too Many Linked Lists
- Tiago's Rust first steps
- Rust By Example
- Rust By Practice
- Rustlings
- The Rust Programming Language
Follow these steps to set up Substreams locally using a different approach:
-
Begin by creating a new folder and cloning the repository. You can clone it from this link.
-
Install the necessary dependencies:
-
Install the Rust programming language, which is used for developing custom logic. You can install Rust in various ways, but for simplicity, execute the following commands:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source $HOME/.cargo/env -
Install
protoc, the Protocol Buffer compiler required for generating code in Rust and other languages from the protobuf definitions. Refer to the official protocol buffer compiler documentation for installation instructions. -
Install
protoc-gen-prost, a tool that helps generate Rust structures from protobuf definitions for use in Substreams modules. Install it by running:cargo install protoc-gen-prostNote: If you forget to install
protocbefore generating the definitions, you may encounter an error mentioningcmakenot being defined. Installingprotocis necessary as a fallback. -
Install
buf, a tool that simplifies the generation of typed structures in any language. It simplifies the usage ofprotocand supports Substreams packages. Visit https://buf.build for installation instructions.
-
-
Obtain the
substreamsCLI tool:-
For macOS users, install it using
brew:brew install streamingfast/tap/substreams -
Alternatively, download the pre-compiled binary for your platform:
# Replace the URL with the correct binary for your platform wget https://github.com/streamingfast/substreams/releases/download/v0.0.12/substreams_0.0.12_linux_x86_64.tar.gz tar -xzvf substreams_0.0.12_linux_x86_64.tar.gz export PATH="`pwd`:$PATH"Make sure to visit https://github.com/streamingfast/substreams/releases and use the latest available release.
-
-
Validate the installation by checking if the
substreamsCLI works correctly:substreams -v version (...) -
Generating Protobuf:
Use the following command to generate Protobuf code:
substreams protogen ./substreams.yaml --exclude-paths="sf/ethereum,sf/substreams,google"
- Compilation:
Now, it's time to build the WASM binary and Protobuf definitions. Execute the following command:
cargo build --target wasm32-unknown-unknown --release
- Running the Substream:
Finally, you can run the example Substream. Make sure you are in the project's root directory before executing the following commands:
To run map module
substreams run -e api-dev.streamingfast.io:443 substreams.yaml map_transfers --start-block 12292922 --stop-block +1
To run the store module (and the map module in the background):
substreams run -e api-dev.streamingfast.io:443 substreams.yaml store_transfers --start-block 12292922 --stop-block +1
-
If you find the list helpful, please make sure to ⭐ star it!