simulateTransaction method simulates sending a transaction. This method does not send a transaction, but rather runs the transaction and returns the result of the execution.
This method is useful for predicting how a transaction will affect the state of the blockchain without actually committing any changes. It can be used to estimate transaction fees, check for potential errors, and understand the effects of a transaction before sending it.
transaction (string, required) — a base64 or base58 encoded string representing the transaction to simulate.config (object, optional) — configuration object containing:
encoding (string) — encoding used for the transaction data. Values: base58 (deprecated), base64 (recommended). Default: base58.commitment (string) — the bank state to simulate against. Default: finalized.sigVerify (boolean) — when true, verify transaction signatures. Default: false. Conflicts with replaceRecentBlockhash.replaceRecentBlockhash (boolean) — when true, replace the transaction’s recent blockhash with the most recent blockhash from the bank. Default: false. Useful for simulating transactions with expired blockhashes. Conflicts with sigVerify.minContextSlot (integer) — the minimum slot at which the request can be evaluated.innerInstructions (boolean) — when true, include inner instructions in the response. Default: false.accounts (object) — configuration for returning post-simulation account state:
addresses (array of strings) — array of account addresses to return.encoding (string) — encoding for the returned account data. Values: base64, base64+zstd, jsonParsed.result object with:
err — null if the simulation was successful, otherwise a transaction error object.logs (array of strings) — log messages the transaction produced during simulation.unitsConsumed (u64) — number of compute units consumed by the transaction.accounts — an array of account objects (or null) corresponding to the accounts.addresses request field.returnData — data returned by the last program that invoked sol_set_return_data. Contains programId (string) and data ([base64_string, "base64"] tuple).innerInstructions — array of inner instruction sets (when innerInstructions: true in the request). Each set contains index (the instruction index) and instructions (array of inner instruction objects).fee (u64, nullable) — the transaction fee in lamports.preBalances (array of u64) — account balances before the simulation.postBalances (array of u64) — account balances after the simulation.preTokenBalances — token balances before the simulation.postTokenBalances — token balances after the simulation.loadedAddresses — addresses loaded from address lookup tables. Contains writable (array of strings) and readonly (array of strings).replacementBlockhash — present when replaceRecentBlockhash: true. Contains blockhash (string) and lastValidBlockHeight (u64).simulateTransaction is to estimate compute units, predict fee costs, and verify that a transaction will succeed before submitting it via sendTransaction. This is especially useful for:
ComputeBudgetProgram.setComputeUnitLimitlogs and innerInstructionspreTokenBalances and postTokenBalancesaccounts config