simulatetransaction

Solana RPC

Archive Method

Only on the full archive nodes. Complex queries might take longer and incur additional cost

How to Use It

// yarn add @tatumio/tatum

import { TatumSDK, Solana, Network } from '@tatumio/tatum'

const tatum = (await TatumSDK.init) < Solana > { network: Network.SOLANA }

const transaction =
  'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDArczbMia1tLmq7zz4DinMNN0pJ1JtLdqIJPUw3YrGCzYAMHBsgN27lcgB6H2WQvFgyZuJYHa46puOQo9yQ8CVQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp20C7Wj2aiuk5TReAXo+VTVg8QTHjs0UjNMMKCvpzZ+ABAgEBARU='

const options = {
  encoding: 'base64',
} // optional

const res = await tatum.rpc.simulateTransaction(transaction, options)

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs

Overview

The simulateTransaction method is used to simulate sending a transaction without actually submitting it to the cluster. This can be useful for debugging and testing purposes.

Parameters

  • transaction: (string, required) Transaction, as an encoded string. The transaction must have a valid blockhash, but is not required to be signed.
  • options (object, optional): Configuration object containing various options for the request. This includes:
    • commitment (string, optional): Commitment level to simulate the transaction at. Default is 'finalized'.
      • Values: finalised confirmed processed
    • sigVerify (boolean, optional): If true, the transaction signatures will be verified. This conflicts with replaceRecentBlockhash.
    • replaceRecentBlockhash (boolean, optional): If true, the transaction's recent blockhash will be replaced with the most recent blockhash. This conflicts with sigVerify.
    • minContextSlot (number, optional): The minimum slot that the request can be evaluated at.
    • encoding (string, optional): Encoding used for the transaction data. Values can be base58 or base64. Default is base58.
    • accounts (object, optional): Accounts configuration object. This includes:
      • addresses: (array of strings, optional) An array of accounts to return, as base-58 encoded strings.
      • encoding: (string, optional) Encoding for returned Account data. Values can be base64, base58, base64+zstd, jsonParsed.

Return Object

The method returns an RpcResponse object with value set to a JSON object with the following fields:

  • err: Error if transaction failed, null if transaction succeeded.

  • logs: Array of log messages the transaction instructions output during execution. Null if simulation failed before the transaction was able to execute (for example due to an invalid blockhash or signature verification failure)

  • accounts: Array of accounts with the same length as the accounts.addresses array in the request. Each Account object resolves to either:

    • null - If the account doesn't exist or if err is not null
    • object - Otherwise, a JSON object containing:
      • lamports: Number of lamports assigned to this account, as a u64
      • owner: Base-58 encoded Pubkey of the program this account has been assigned to
      • data: Data associated with the account, either as encoded binary data or JSON format {<program>: <state>} - depending on encoding parameter
      • executable: Boolean indicating if the account contains a program (and is strictly read-only)
      • rentEpoch: The epoch at which this account will next owe rent, as u64
  • unitsConsumed: The number of compute budget units consumed during the processing of this transaction.

  • returnData: The most-recent return data generated by an instruction in the transaction

    with the following fields:

    • programId: The program that generated the return data, as base-58 encoded Pubkey
    • data: The return data itself, as base-64 encoded binary data

JSON-RPC Request Example

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "simulateTransaction",
  "params": [
    "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDArczbMia1tLmq7zz4DinMNN0pJ1JtLdqIJPUw3YrGCzYAMHBsgN27lcgB6H2WQvFgyZuJYHa46puOQo9yQ8CVQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp20C7Wj2aiuk5TReAXo+VTVg8QTHjs0UjNMMKCvpzZ+ABAgEBARU=",
    {
      "encoding": "base64"
    }
  ]
}

JSON-RPC Response Example

{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "slot": 218
    },
    "value": {
      "err": null,
      "accounts": null,
      "logs": [
        "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri invoke [1]",
        "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri consumed 2366 of 1400000 compute units",
        "Program return: 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri KgAAAAAAAAA=",
        "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri success"
      ],
      "returnData": {
        "data": ["Kg==", "base64"],
        "programId": "83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri"
      },
      "unitsConsumed": 2366
    }
  },
  "id": 1
}

\