Expand description
§safe-rs
A Rust library for interacting with Safe v1.4.1 smart accounts.
§Features
- Fluent builder API for multicall transactions
- Local fork simulation using foundry-fork-db + revm
- Seamless integration with alloy’s
sol!macro ecosystem - Single-owner (1/1 threshold) Safe support
§Quick Start
ⓘ
use safe_rs::{Safe, contracts::IERC20};
use alloy::primitives::{address, U256};
// Connect to a Safe
let safe = Safe::connect(provider, signer, safe_address).await?;
// Execute a multicall with typed calls (with simulation)
safe.batch()
.add_typed(usdc, IERC20::transferCall { to: recipient, amount: U256::from(1000) })
.add_typed(usdc, IERC20::approveCall { spender, amount: U256::MAX })
.simulate().await?
.execute().await?;
// Or execute without simulation (gas estimated via RPC)
safe.batch()
.add_typed(usdc, IERC20::transferCall { to: recipient, amount: U256::from(1000) })
.execute().await?;§Builder API
The SafeBuilder provides a fluent API for constructing transactions:
ⓘ
// Build and simulate
let builder = safe.batch()
.add_typed(token, call)
.simulate().await?;
// Inspect simulation results
if let Some(result) = builder.simulation_result() {
println!("Gas used: {}", result.gas_used);
}
// Execute the transaction
let result = builder.execute().await?;Re-exports§
pub use account::Account;pub use chain::ChainAddresses;pub use chain::ChainConfig;pub use contracts::IERC20;pub use contracts::IMultiSend;pub use contracts::IMultiSendCallOnly;pub use contracts::ISafe;pub use contracts::ISafeProxyFactory;pub use contracts::ISafeSetup;pub use create2::compute_create2_address;pub use create2::encode_setup_call;pub use encoding::SafeTxParams;pub use eoa::Eoa;pub use eoa::EoaBatchResult;pub use eoa::EoaBuilder;pub use eoa::EoaTxResult;pub use error::Error;pub use error::Result;pub use safe::is_safe;pub use safe::ExecutionResult;pub use safe::SafeBuilder;pub use safe::Safe;pub use safe::SAFE_SINGLETON_SLOT;pub use simulation::ForkSimulator;pub use simulation::SimulationResult;pub use types::BatchResult;pub use types::BatchSimulationResult;pub use types::Call;pub use types::CallBuilder;pub use types::Operation;pub use types::SafeCall;pub use types::TypedCall;pub use wallet::Wallet;pub use wallet::WalletBuilder;pub use wallet::WalletConfig;
Modules§
- account
- Shared account trait for Safe and EOA wallets
- chain
- Chain configuration and contract addresses
- contracts
- Contract ABI definitions for Safe v1.4.1
- create2
- CREATE2 address computation for Safe proxy deployment
- encoding
- Encoding utilities for Safe transactions
- eoa
- EOA (Externally Owned Account) fallback mode
- error
- Error types for safe-rs
- safe
- Safe client and SafeBuilder implementation
- signing
- Signature generation for Safe transactions
- simulation
- Transaction simulation using fork database and revm
- types
- Type definitions for Safe transactions
- wallet
- Generic Wallet type for Safe and EOA accounts
Structs§
- Account
State - Represents the state of an account.
- Address
- An Ethereum address, 20 bytes in length.
- AnyNetwork
- Types for a catch-all network.
- Bytes
- Wrapper type around
bytes::Bytesto support “0x” prefixed hex strings. - Call
Trace Arena - An arena of recorded traces.
- Diff
Mode - Represents the account states before and after the transaction is executed.
Traits§
- Provider
- Ethereum JSON-RPC interface.
Type Aliases§
- EoaWallet
- Type alias for an EOA wallet
- Safe
Wallet - Type alias for a Safe wallet
- U256
- 256-bit unsigned integer type, consisting of 4, 64-bit limbs.