tenderly_rs/
lib.rs

1//! # Tenderly Rust SDK
2//!
3//! An unofficial Rust client library for the [Tenderly API](https://docs.tenderly.co/),
4//! providing transaction simulation, contract verification, and wallet management functionality.
5//!
6//! ## Features
7//!
8//! - **Transaction Simulation** - Simulate individual transactions or bundles with detailed
9//!   execution traces
10//! - **Contract Verification** - Verify smart contracts on Tenderly with source code and compiler
11//!   settings
12//! - **Wallet Management** - Add, update, and manage wallet addresses in your project
13//! - **Contract Management** - Add, update, and query contracts with metadata and tags
14//! - **State Overrides** - Simulate transactions with custom state modifications (balance, storage,
15//!   etc.)
16//! - **Async/Await** - Built with Tokio for high-performance async operations
17//! - **Type Safety** - Strongly typed API with comprehensive error handling
18//! - **Multi-Network** - Support for 70+ blockchain networks (Ethereum, Arbitrum, Optimism, Base,
19//!   Polygon, etc.)
20//!
21//! ## Quick Start
22//!
23//! ```rust,no_run
24//! use tenderly_rs::{
25//!     Network,
26//!     Tenderly,
27//!     TenderlyConfiguration,
28//! };
29//!
30//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
31//! let tenderly = Tenderly::new(TenderlyConfiguration::new(
32//!     "account_name".to_string(),
33//!     "project_name".to_string(),
34//!     "access_key".to_string(),
35//!     Network::Mainnet,
36//! ))?;
37//!
38//! // Use tenderly.simulator, tenderly.contracts, or tenderly.wallets
39//! # Ok(())
40//! # }
41//! ```
42//!
43//! ## Module Overview
44//!
45//! ### [`core`]
46//! Main [`Tenderly`] client and configuration types. Provides the entry point to the SDK.
47//!
48//! ### [`executors`]
49//! Transaction simulation executors. Contains the [`Simulator`] struct
50//! for running transaction and bundle simulations.
51//!
52//! ### [`services`]
53//! Contract and wallet management services. Provides [`ContractRepository`]
54//! and [`WalletRepository`] for managing contracts and wallets.
55//!
56//! ### [`types`]
57//! Common types and enums including [`Network`] for supported blockchain networks,
58//! [`TenderlyConfiguration`] for SDK configuration, and other utility types.
59//!
60//! ### [`errors`]
61//! Comprehensive error types for the SDK. All errors implement `std::error::Error` and can be
62//! converted to [`GeneralError`] for unified error handling.
63//!
64//! ## Usage Examples
65//!
66//! ### Transaction Simulation
67//!
68//! ```rust,no_run
69//! use tenderly_rs::{
70//!     executors::types::*,
71//!     Network,
72//!     Tenderly,
73//!     TenderlyConfiguration,
74//! };
75//!
76//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
77//! let tenderly = Tenderly::new(TenderlyConfiguration::new(
78//!     "account".to_string(),
79//!     "project".to_string(),
80//!     "key".to_string(),
81//!     Network::Mainnet,
82//! ))?;
83//!
84//! let transaction = TransactionParameters {
85//!     from: "0x...".to_string(),
86//!     to: "0x...".to_string(),
87//!     gas: 21000,
88//!     gas_price: "0".to_string(),
89//!     value: "0".to_string(),
90//!     input: "0x...".to_string(),
91//!     max_fee_per_gas: None,
92//!     max_priority_fee_per_gas: None,
93//!     access_list: None,
94//! };
95//!
96//! let simulation = SimulationParameters {
97//!     transaction,
98//!     block_number: 12345678,
99//!     overrides: None,
100//! };
101//!
102//! let result = tenderly.simulator.simulate_transaction(&simulation).await?;
103//! println!("Gas used: {}", result.gas_used.unwrap_or(0));
104//! # Ok(())
105//! # }
106//! ```
107//!
108//! ### Contract Verification
109//!
110//! ```rust,no_run
111//! use tenderly_rs::{Network, Tenderly, TenderlyConfiguration};
112//! use tenderly_rs::services::contracts::types::*;
113//! use std::collections::HashMap;
114//!
115//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
116//! let tenderly = Tenderly::new(TenderlyConfiguration::new(
117//!     "account".to_string(),
118//!     "project".to_string(),
119//!     "key".to_string(),
120//!     Network::Sepolia,
121//! ))?;
122//!
123//! let mut sources = HashMap::new();
124//! sources.insert("Counter.sol".to_string(), SourceContent {
125//!     content: r#"pragma solidity ^0.8.0; contract Counter { uint public count; }"#.to_string(),
126//! });
127//!
128//! let solc_config = SolcConfig {
129//!     version: "v0.8.18".to_string(),
130//!     sources,
131//!     settings: serde_json::json!({"optimizer": {"enabled": false}}),
132//! };
133//!
134//! let verification_request = VerificationRequest {
135//!     contract_to_verify: "Counter.sol:Counter".to_string(),
136//!     solc: solc_config,
137//!     config: VerificationConfig {
138//!         mode: VerificationMode::Public,
139//!     },
140//! };
141//!
142//! let verified = tenderly.contracts.verify("0x...", &verification_request).await?;
143//! # Ok(())
144//! # }
145//! ```
146//!
147//! ### Contract Management
148//!
149//! ```rust,no_run
150//! use tenderly_rs::{
151//!     services::ContractData,
152//!     Network,
153//!     Tenderly,
154//!     TenderlyConfiguration,
155//! };
156//!
157//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
158//! let tenderly = Tenderly::new(TenderlyConfiguration::new(
159//!     "account".to_string(),
160//!     "project".to_string(),
161//!     "key".to_string(),
162//!     Network::Mainnet,
163//! ))?;
164//!
165//! // Add a contract
166//! let contract = tenderly
167//!     .contracts
168//!     .add(
169//!         "0x6b175474e89094c44da98b954eedeac495271d0f",
170//!         Some(&ContractData {
171//!             display_name: Some("DAI Token".to_string()),
172//!         }),
173//!     )
174//!     .await?;
175//!
176//! // Get all contracts
177//! let contracts = tenderly.contracts.get_all().await?;
178//!
179//! // Get a specific contract
180//! let contract = tenderly
181//!     .contracts
182//!     .get("0x6b175474e89094c44da98b954eedeac495271d0f")
183//!     .await?;
184//! # Ok(())
185//! # }
186//! ```
187//!
188//! ### Wallet Management
189//!
190//! ```rust,no_run
191//! use tenderly_rs::{
192//!     services::WalletData,
193//!     Network,
194//!     Tenderly,
195//!     TenderlyConfiguration,
196//! };
197//!
198//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
199//! let tenderly = Tenderly::new(TenderlyConfiguration::new(
200//!     "account".to_string(),
201//!     "project".to_string(),
202//!     "key".to_string(),
203//!     Network::Mainnet,
204//! ))?;
205//!
206//! // Add a wallet
207//! let wallet = tenderly
208//!     .wallets
209//!     .add(
210//!         "0x...",
211//!         Some(&WalletData {
212//!             display_name: Some("My Wallet".to_string()),
213//!         }),
214//!     )
215//!     .await?;
216//!
217//! // Get all wallets
218//! let wallets = tenderly.wallets.get_all().await?;
219//! # Ok(())
220//! # }
221//! ```
222//!
223//! ## State Overrides
224//!
225//! Simulate transactions with custom state modifications:
226//!
227//! ```rust,no_run
228//! use std::collections::HashMap;
229//! use tenderly_rs::executors::types::*;
230//!
231//! let mut overrides: SimulationParametersOverrides = HashMap::new();
232//! let mut state_override = serde_json::Map::new();
233//! state_override.insert(
234//!     "balance".to_string(),
235//!     serde_json::json!("0x1000000000000000000"),
236//! );
237//!
238//! overrides.insert(
239//!     "0x...".to_string(),
240//!     SimulationParametersOverride {
241//!         nonce: None,
242//!         code: None,
243//!         balance: Some("1000000000000000000".to_string()),
244//!         state: Some(serde_json::Value::Object(state_override)),
245//!     },
246//! );
247//! ```
248//!
249//! ## Supported Networks
250//!
251//! The SDK supports all networks supported by Tenderly, including:
252//!
253//! - **Ethereum**: Mainnet, Sepolia, Holesky
254//! - **L2s**: Arbitrum One, Optimism, Base, Polygon, Blast
255//! - **Testnets**: Sepolia, Goerli, Mumbai, Arbitrum Sepolia
256//! - And 70+ more networks
257//!
258//! See the [`Network`] enum for the complete list.
259//!
260//! ## Error Handling
261//!
262//! All API methods return `Result<T, GeneralError>`. Handle errors comprehensively:
263//!
264//! ```rust,no_run
265//! use tenderly_rs::{
266//!     errors::GeneralError,
267//!     executors::types::*,
268//!     Network,
269//!     Tenderly,
270//!     TenderlyConfiguration,
271//! };
272//!
273//! # async fn example() -> Result<(), GeneralError> {
274//! let tenderly = Tenderly::new(TenderlyConfiguration::new(
275//!     "account".to_string(),
276//!     "project".to_string(),
277//!     "key".to_string(),
278//!     Network::Mainnet,
279//! ))?;
280//!
281//! let params = SimulationParameters {
282//!     transaction: TransactionParameters {
283//!         from: "0x...".to_string(),
284//!         to: "0x...".to_string(),
285//!         gas: 21000,
286//!         gas_price: "0".to_string(),
287//!         value: "0".to_string(),
288//!         input: "0x...".to_string(),
289//!         max_fee_per_gas: None,
290//!         max_priority_fee_per_gas: None,
291//!         access_list: None,
292//!     },
293//!     block_number: 12345678,
294//!     overrides: None,
295//! };
296//!
297//! match tenderly.simulator.simulate_transaction(&params).await {
298//!     Ok(result) => println!("Success: {:?}", result),
299//!     Err(GeneralError::ApiError(e)) => eprintln!("API Error: {}", e.error.message),
300//!     Err(GeneralError::NotFound(e)) => eprintln!("Not Found: {}", e.message),
301//!     Err(e) => eprintln!("Error: {:?}", e),
302//! }
303//! # Ok(())
304//! # }
305//! ```
306//!
307//! ## Examples
308//!
309//! See the [`examples/`](https://github.com/codeesura/tenderly-rs/tree/main/examples) directory
310//! for complete usage examples including:
311//!
312//! - `simulate_transaction.rs` - Single transaction simulation
313//! - `simulate_bundle.rs` - Transaction bundle simulation with state overrides
314//! - `simulate_bundle_simple.rs` - Simple bundle simulation
315//! - `verify_contract.rs` - Contract verification
316//! - `add_contracts.rs` - Contract management
317//! - `add_wallets.rs` - Wallet management
318//!
319//! ## Requirements
320//!
321//! - Rust 1.70 or higher
322//! - Tokio runtime (for async operations)
323//!
324//! ## License
325//!
326//! This project is licensed under the MIT License - see the LICENSE file for details.
327//!
328//! **Note**: This is an unofficial, community-maintained Rust port of the
329//! [Tenderly TypeScript SDK](https://github.com/Tenderly/tenderly-sdk).
330//! It is not affiliated with or endorsed by Tenderly.
331
332pub mod constants;
333pub mod core;
334pub mod errors;
335pub mod executors;
336pub mod helpers;
337pub mod services;
338pub mod types;
339
340pub use core::{
341    PartialConfiguration,
342    Tenderly,
343};
344
345pub use constants::{
346    TENDERLY_API_BASE_URL,
347    TENDERLY_SDK_VERSION,
348};
349pub use errors::*;
350pub use executors::*;
351pub use helpers::*;
352pub use services::{
353    contracts::types::{
354        Contract,
355        ContractRequest,
356        GetByParams,
357        SolcConfig,
358        SourceContent,
359        TenderlyContract,
360        UpdateContractRequest,
361        VerificationConfig,
362        VerificationMode,
363        VerificationRequest,
364    },
365    wallets::types::{
366        UpdateWalletRequest,
367        Wallet,
368        WalletRequest,
369    },
370    *,
371};
372pub use types::*;