Expand description
Transaction simulation for pre-flight validation.
This module provides utilities for simulating transactions before submission to predict outcomes, estimate gas costs, and catch errors early.
§Overview
Transaction simulation allows you to:
- Predict success/failure before spending gas
- Estimate gas costs more accurately than the gas estimator
- Debug transactions by examining execution details
- Validate payloads before committing to transactions
Multi-agent and fee-payer transactions can be simulated without collecting
signatures first: use crate::Aptos::simulate_multi_agent and
crate::Aptos::simulate_fee_payer with a raw multi-agent or fee-payer transaction.
These use SimulateQueryOptions when you need gas estimation query parameters
(e.g. estimate_gas_unit_price, estimate_max_gas_amount) on the simulate endpoint.
crate::api::FullnodeClient::simulate_transaction rewrites authenticators
(see crate::transaction::types::SignedTransaction::for_simulate_endpoint) before
sending so the fullnode never receives a cryptographically valid signature on the
simulate path.
§Example
use aptos_sdk::{Aptos, AptosConfig};
use aptos_sdk::account::{Account, Ed25519Account};
let aptos = Aptos::new(AptosConfig::testnet())?;
let account = Ed25519Account::generate();
let payload = aptos_sdk::transaction::EntryFunction::apt_transfer(
Ed25519Account::generate().address(),
1_000_000,
)?.into();
let result = aptos.simulate(&account, payload).await?;
if result.success() {
println!("Estimated gas: {}", result.gas_used());
} else {
println!("Would fail: {}", result.vm_status());
}Structs§
- Simulate
Query Options - Query options for the fullnode
/transactions/simulateendpoint. - Simulated
Event - An event from a simulated transaction.
- Simulation
Options - Options for simulation.
- Simulation
Result - Result of a transaction simulation.
- State
Change - A state change from a simulated transaction.
- VmError
- Detailed VM error information.
Enums§
- VmError
Category - Categories of VM errors.