Expand description
§Tenderly Rust SDK
An unofficial Rust client library for the Tenderly API, providing transaction simulation, contract verification, and wallet management functionality.
§Features
- Transaction Simulation - Simulate individual transactions or bundles with detailed execution traces
- Contract Verification - Verify smart contracts on Tenderly with source code and compiler settings
- Wallet Management - Add, update, and manage wallet addresses in your project
- Contract Management - Add, update, and query contracts with metadata and tags
- State Overrides - Simulate transactions with custom state modifications (balance, storage, etc.)
- Async/Await - Built with Tokio for high-performance async operations
- Type Safety - Strongly typed API with comprehensive error handling
- Multi-Network - Support for 70+ blockchain networks (Ethereum, Arbitrum, Optimism, Base, Polygon, etc.)
§Quick Start
use tenderly_rs::{
Network,
Tenderly,
TenderlyConfiguration,
};
let tenderly = Tenderly::new(TenderlyConfiguration::new(
"account_name".to_string(),
"project_name".to_string(),
"access_key".to_string(),
Network::Mainnet,
))?;
// Use tenderly.simulator, tenderly.contracts, or tenderly.wallets§Module Overview
§core
Main Tenderly client and configuration types. Provides the entry point to the SDK.
§executors
Transaction simulation executors. Contains the Simulator struct
for running transaction and bundle simulations.
§services
Contract and wallet management services. Provides ContractRepository
and WalletRepository for managing contracts and wallets.
§types
Common types and enums including Network for supported blockchain networks,
TenderlyConfiguration for SDK configuration, and other utility types.
§errors
Comprehensive error types for the SDK. All errors implement std::error::Error and can be
converted to GeneralError for unified error handling.
§Usage Examples
§Transaction Simulation
use tenderly_rs::{
executors::types::*,
Network,
Tenderly,
TenderlyConfiguration,
};
let tenderly = Tenderly::new(TenderlyConfiguration::new(
"account".to_string(),
"project".to_string(),
"key".to_string(),
Network::Mainnet,
))?;
let transaction = TransactionParameters {
from: "0x...".to_string(),
to: "0x...".to_string(),
gas: 21000,
gas_price: "0".to_string(),
value: "0".to_string(),
input: "0x...".to_string(),
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
access_list: None,
};
let simulation = SimulationParameters {
transaction,
block_number: 12345678,
overrides: None,
};
let result = tenderly.simulator.simulate_transaction(&simulation).await?;
println!("Gas used: {}", result.gas_used.unwrap_or(0));§Contract Verification
use tenderly_rs::{Network, Tenderly, TenderlyConfiguration};
use tenderly_rs::services::contracts::types::*;
use std::collections::HashMap;
let tenderly = Tenderly::new(TenderlyConfiguration::new(
"account".to_string(),
"project".to_string(),
"key".to_string(),
Network::Sepolia,
))?;
let mut sources = HashMap::new();
sources.insert("Counter.sol".to_string(), SourceContent {
content: r#"pragma solidity ^0.8.0; contract Counter { uint public count; }"#.to_string(),
});
let solc_config = SolcConfig {
version: "v0.8.18".to_string(),
sources,
settings: serde_json::json!({"optimizer": {"enabled": false}}),
};
let verification_request = VerificationRequest {
contract_to_verify: "Counter.sol:Counter".to_string(),
solc: solc_config,
config: VerificationConfig {
mode: VerificationMode::Public,
},
};
let verified = tenderly.contracts.verify("0x...", &verification_request).await?;§Contract Management
use tenderly_rs::{
services::ContractData,
Network,
Tenderly,
TenderlyConfiguration,
};
let tenderly = Tenderly::new(TenderlyConfiguration::new(
"account".to_string(),
"project".to_string(),
"key".to_string(),
Network::Mainnet,
))?;
// Add a contract
let contract = tenderly
.contracts
.add(
"0x6b175474e89094c44da98b954eedeac495271d0f",
Some(&ContractData {
display_name: Some("DAI Token".to_string()),
}),
)
.await?;
// Get all contracts
let contracts = tenderly.contracts.get_all().await?;
// Get a specific contract
let contract = tenderly
.contracts
.get("0x6b175474e89094c44da98b954eedeac495271d0f")
.await?;§Wallet Management
use tenderly_rs::{
services::WalletData,
Network,
Tenderly,
TenderlyConfiguration,
};
let tenderly = Tenderly::new(TenderlyConfiguration::new(
"account".to_string(),
"project".to_string(),
"key".to_string(),
Network::Mainnet,
))?;
// Add a wallet
let wallet = tenderly
.wallets
.add(
"0x...",
Some(&WalletData {
display_name: Some("My Wallet".to_string()),
}),
)
.await?;
// Get all wallets
let wallets = tenderly.wallets.get_all().await?;§State Overrides
Simulate transactions with custom state modifications:
use std::collections::HashMap;
use tenderly_rs::executors::types::*;
let mut overrides: SimulationParametersOverrides = HashMap::new();
let mut state_override = serde_json::Map::new();
state_override.insert(
"balance".to_string(),
serde_json::json!("0x1000000000000000000"),
);
overrides.insert(
"0x...".to_string(),
SimulationParametersOverride {
nonce: None,
code: None,
balance: Some("1000000000000000000".to_string()),
state: Some(serde_json::Value::Object(state_override)),
},
);§Supported Networks
The SDK supports all networks supported by Tenderly, including:
- Ethereum: Mainnet, Sepolia, Holesky
- L2s: Arbitrum One, Optimism, Base, Polygon, Blast
- Testnets: Sepolia, Goerli, Mumbai, Arbitrum Sepolia
- And 70+ more networks
See the Network enum for the complete list.
§Error Handling
All API methods return Result<T, GeneralError>. Handle errors comprehensively:
use tenderly_rs::{
errors::GeneralError,
executors::types::*,
Network,
Tenderly,
TenderlyConfiguration,
};
let tenderly = Tenderly::new(TenderlyConfiguration::new(
"account".to_string(),
"project".to_string(),
"key".to_string(),
Network::Mainnet,
))?;
let params = SimulationParameters {
transaction: TransactionParameters {
from: "0x...".to_string(),
to: "0x...".to_string(),
gas: 21000,
gas_price: "0".to_string(),
value: "0".to_string(),
input: "0x...".to_string(),
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
access_list: None,
},
block_number: 12345678,
overrides: None,
};
match tenderly.simulator.simulate_transaction(¶ms).await {
Ok(result) => println!("Success: {:?}", result),
Err(GeneralError::ApiError(e)) => eprintln!("API Error: {}", e.error.message),
Err(GeneralError::NotFound(e)) => eprintln!("Not Found: {}", e.message),
Err(e) => eprintln!("Error: {:?}", e),
}§Examples
See the examples/ directory
for complete usage examples including:
simulate_transaction.rs- Single transaction simulationsimulate_bundle.rs- Transaction bundle simulation with state overridessimulate_bundle_simple.rs- Simple bundle simulationverify_contract.rs- Contract verificationadd_contracts.rs- Contract managementadd_wallets.rs- Wallet management
§Requirements
- Rust 1.70 or higher
- Tokio runtime (for async operations)
§License
This project is licensed under the MIT License - see the LICENSE file for details.
Note: This is an unofficial, community-maintained Rust port of the Tenderly TypeScript SDK. It is not affiliated with or endorsed by Tenderly.
Re-exports§
pub use core::PartialConfiguration;pub use core::Tenderly;pub use constants::TENDERLY_API_BASE_URL;pub use constants::TENDERLY_SDK_VERSION;pub use services::contracts::types::Contract;pub use services::contracts::types::ContractRequest;pub use services::contracts::types::GetByParams;pub use services::contracts::types::SolcConfig;pub use services::contracts::types::SourceContent;pub use services::contracts::types::TenderlyContract;pub use services::contracts::types::UpdateContractRequest;pub use services::contracts::types::VerificationConfig;pub use services::contracts::types::VerificationMode;pub use services::contracts::types::VerificationRequest;pub use services::wallets::types::UpdateWalletRequest;pub use services::wallets::types::Wallet;pub use services::wallets::types::WalletRequest;pub use errors::*;pub use executors::*;pub use helpers::*;pub use services::*;pub use types::*;