simulateTransaction – Solana

The simulateTransaction JSON-RPC method allows developers to simulate sending a Solana transaction without broadcasting it to the network.

The simulateTransaction RPC Solana method executes a transaction in a simulated environment.

It verifies signatures and blockhash validity, returning the execution logs and account state changes without modifying the blockchain state.

Supported Networks

This method is accessible via the following API endpoints:

  • Mainnet

  • Devnet

Parameters

Required Parameters

  • string (required): The transaction encoded as a base-58 or base-64 string.

Optional Parameters

  • object (optional): A configuration object containing:

    • commitment (string): Defines the finality level for the simulation.

      • Default: finalized

    • sigVerify (bool): Enable signature verification.

      • Default: false

    • replaceRecentBlockhash (bool): Replace the transaction blockhash with the most recent one.

      • Default: false

    • minContextSlot (number): The minimum slot for evaluating the request.

    • encoding (string): Encoding for the transaction data.

      • Default: base58 (DEPRECATED)

      • Supported: base58, base64

    • innerInstructions (bool): Include inner instructions in the response.

    • accounts (object): Configuration for account data retrieval:

      • addresses (array): List of account addresses.

      • encoding (string): Encoding format for account data.

        • Default: base64

        • Supported: base58, base64, base64+zstd, jsonParsed

Result

The response returns an RpcResponse JSON object containing simulation results.

Result Fields

  • err (object|string|null): Error details if the simulation fails.

  • logs (array|null): Execution logs generated by transaction instructions.

  • accounts (array|null): Account data requested during the simulation.

  • unitsConsumed (u64): Compute units consumed by the simulation.

  • returnData (object|null): Return data produced by the transaction instructions.

Request Example

API Endpoints

https://go.getblock.io/<ACCESS-TOKEN>/

cURL Example

curl --location "https://go.getblock.io/<ACCESS-TOKEN>/" -XPOST \
--header "Content-Type: application/json" \
--data '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "simulateTransaction",
    "params": [
      "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDArczbMia1tLmq7zz4DinMNN0pJ1JtLdqIJPUw3YrGCzYAMHBsgN27lcgB6H2WQvFgyZuJYHa46puOQo9yQ8CVQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp20C7Wj2aiuk5TReAXo+VTVg8QTHjs0UjNMMKCvpzZ+ABAgEBARU=",
      {
        "encoding": "base64"
      }
    ]
}'

Response

A successful request returns the simulation results.

simulateTransaction Example Response

{
  "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
}

Error Handling

Common simulateTransaction error scenarios:

  • Invalid transaction: Incorrect transaction format.

  • Expired blockhash: Blockhash has expired.

  • Signature verification failure: Invalid transaction signatures.

  • Network issues: Problems with the Solana JSON-RPC API endpoints.

Example Error Response

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32003,
    "message": "Transaction failed: Blockhash not found"
  },
  "id": 1
}

Use Cases

The Solana simulateTransaction method is useful for:

  • Testing transaction logic without broadcasting it.

  • Analyzing program logs and compute unit consumption.

  • Validating transactions before submission.

  • Debugging failed transactions with detailed logs.

Code simulateTransaction Example – Web3 Integration

const axios = require('axios');

const url = "https://go.getblock.io/<ACCESS-TOKEN>/";
const headers = { "Content-Type": "application/json" };

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

const simulateTransaction = async () => {
  try {
    const response = await axios.post(url, payload, { headers });

    if (response.status === 200 && response.data.result) {
      console.log("Simulation Result:", response.data.result);
    } else {
      console.error("Unexpected response:", response.data);
    }
  } catch (error) {
    console.error("simulateTransaction error:", error.response?.data || error.message);
  }
};

simulateTransaction();

Integration with Web3

By integrating Web3 simulateTransaction into Solana’s Core API, developers can test transactions, analyze logs, and validate execution paths without committing state changes. This JSON-RPC method is essential for debugging and optimizing blockchain applications.

Last updated