Skip to content

Rust

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

To install the Tempo extension, you will need to install Alloy and Tempo:

cargo
cargo add alloy tokio
cargo add tempo-alloy --git https://github.com/tempoxyz/tempo

Configure A 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.

main.rs
use alloy::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?; 
    
  Ok(())
}

Use Actions

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.

main.rs
use alloy::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.