Rust SDK
Tempo distributes a Rust SDK in the form of an Alloy crate. Alloy is a popular Rust crate for interacting with EVM-compatible blockchains.
The Tempo Alloy crate can be used to perform common operations with the chain, such as: querying the chain, sending Tempo Transactions, managing tokens & their AMM pools, and more.
Install the Rust SDK
To install the Tempo extension, you will need to install Alloy and Tempo:
cargo add alloy tokio
cargo add tempo-alloy --git https://github.com/tempoxyz/tempo --tag v1.4.2Configure a Rust provider
To use the Tempo extension crate, you will need to create a Provider using the TempoNetwork. This will enable the usage of Tempo specific types on the Provider instance.
For more information about network types, see the Alloy documentation.
use alloy::providers::ProviderBuilder;
use tempo_alloy::TempoNetwork;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let provider = ProviderBuilder::new_with_network::<TempoNetwork>()
.connect(&std::env::var("RPC_URL").expect("No RPC URL set"))
.await?;
println!("Provider connected successfully");
println!("Chain ID: {provider:?}");
Ok(())
}Use Tempo actions in Rust
Now we are ready to use the provider to interact with the network. We can use the provider to send transactions, read data, and more.
use alloy::providers::{Provider, ProviderBuilder};
use tempo_alloy::TempoNetwork;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let provider = ProviderBuilder::new_with_network::<TempoNetwork>()
.connect(&std::env::var("RPC_URL").expect("No RPC URL set"))
.await?;
println!("{}", provider.get_block_number().await?);
421045
Ok(())
}See the Alloy documentation or the Provider docs for more examples.
Was this helpful?