simulate
Dry-run an unsigned transaction against the latest committed state and return its outcome.
Signature
async fn simulate(&self, tx: UnsignedTx) -> Result<TxOutcome, anyhow::Error>;From impl QueryClient for HttpClient. UnsignedTx and TxOutcome are re-exported by the SDK.
Example
use {
anyhow::Result,
dango_sdk::{HttpClient, SingleSigner},
grug::{NonEmpty, QueryClient, Signer},
};
async fn estimate_gas(
http: &HttpClient,
signer: &SingleSigner<impl dango_sdk::Secret>,
messages: NonEmpty<Vec<grug::Message>>,
) -> Result<u64> {
let unsigned = signer.unsigned_transaction(messages, "dango-1")?;
let outcome = http.simulate(unsigned).await?;
Ok(outcome.gas_used as u64)
}Parameters
tx — UnsignedTx. The transaction body (sender, messages, metadata) without a signature.
Returns
TxOutcome — the simulated outcome, including gas_used, gas_limit, the success/failure result, and emitted events.
Notes
- Simulation runs without consuming nonce or gas on chain. Authentication is skipped.
- Apply your own gas buffer — the report is actual usage, not a recommended limit.
- Builds
UnsignedTxviaSigner::unsigned_transactionto keep thesenderand metadata consistent with whatsign_transactionwill produce.
See also
broadcast_tx— submit a signed version.- Concepts: Transactions — full sign-and-broadcast flow.