simulateTransaction

The simulateTransaction method simulates sending a transaction without actually submitting it to the cluster. This is an invaluable testing and debugging tool that allows developers to see exactly what would happen if a transaction were executed, including all state changes, logs, and potential errors, without spending any fees or modifying on-chain state.

Transaction simulation executes the transaction against the current blockchain state in a sandboxed environment. It processes all instructions, invokes programs, modifies accounts, and generates logs exactly as would happen in real execution, but then discards all changes. This enables developers to preview transaction results, debug complex program interactions, estimate compute units, and catch errors before spending real SOL on failed transactions.

This method is essential for wallet UIs showing transaction previews, debugging program behavior, validating transaction construction before submission, estimating fees and compute units, and testing complex multi-instruction transactions. It significantly improves development speed by catching errors early and provides transparency about what transactions will do before users approve them.


Parameters

parameter
type
description
transaction
string
Transaction as an encoded string. The transaction must have a valid blockhash but does not need valid signatures
config
object
Optional configuration object
config.encoding
string
Encoding for the transaction: 'base58' (slow) or 'base64' (default: 'base58')
config.commitment
string
Commitment level for simulation: 'processed', 'confirmed', or 'finalized' (default: 'finalized')
config.sigVerify
boolean
If true, verify transaction signatures (default: false)
config.replaceRecentBlockhash
boolean
If true, replace the transaction's recent blockhash with the latest blockhash (default: false)
config.accounts
object
Optional. Accounts configuration with encoding and addresses to return
config.minContextSlot
number
Optional. Minimum slot that the request can be evaluated at
Return Object
field
type
description
context
object
RPC response context with slot information
context.slot
number
The slot at which simulation was performed
value
object
Simulation result object
value.err
object|null
Error if transaction would fail, null if successful
value.logs
array
Array of log messages generated during simulation
value.accounts
array|null
Array of accounts with post-transaction state if requested in config
value.unitsConsumed
number
Number of compute units consumed by the transaction
value.returnData
object|null
Return data from the transaction's instructions, if any
Request Example
Request
Response Example
Response

Tip: Set replaceRecentBlockhash: true to avoid blockhash expiration issues during testing. The transaction doesn't need valid signatures unless sigVerify: true. Check logs array for detailed program output - invaluable for debugging. unitsConsumed helps estimate compute budget needs. Simulation uses current state, so results may differ if state changes before actual submission.


Share on
Share on FacebookShare on XShare on LinkedIn
Did you find this page useful?