Rust Dependencies

Substreams Rust APIs

Rust crates overview

The official substreams crate helps developers create module handlers.

Note: If a crate is not available for Substreams, you can use the spkg release for the chain, which includes the Block protobuf model, and generate the Rust structs yourself.

Third-party libraries

Any third-party library capable of compiling wasm32 can be used for execution in Substreams services.

Some libraries include kernel syscalls or other operations unavailable in the Substreams execution environment and cannot be compiled to WASM. The internal functionality of third-party libraries is an essential consideration for Substreams development.

Helpful information people found through the use of third-party libraries and Substreams together include:

  • tiny_keccak: an implementation of Keccak-derived functions specified in FIPS-202, SP800-185, and KangarooTwelve.

Git Versions

Specifying dependencies from Git repositories is possible in Rust, but it is NOT recommended by the Substreams team, as they are not fully tested and can bring bugs to your Substreams project.

The Substreams team recommends using the templates provided in the Examples section as a starting point to develop your Substreams application.

Logs

The substreams crate allows you to log data in the Substreams execution for debugging purposes. The std::println(...) function of Rust won't work in Substreams.

Use the substreams::log::pritnln(...) function in your Rust code to log data during the execution.

#[substreams::handlers::map]
fn all_transactions_without_votes(blk: Block) -> Result<Transactions, substreams::errors::Error> {
    let transactions: Vec<ConfirmedTransaction> = blk.transactions.into_iter().collect();

    substreams::log::println(format!("Number of transactions:{}", transactions.len()));

    Ok(Transactions { transactions })
}

Last updated