simulateTransaction

Learn simulateTransaction use cases, code examples, request parameters, response structure, and tips.

The simulateTransaction RPC method in CoinVera simulates the execution of a signed transaction without broadcasting it to the network. This is commonly used for debugging, testing, and preflight validation before sending a real transaction. It helps catch errors like insufficient funds, failed program logic, or compute unit limits.


✅ Common Use Cases

  • Preflight Testing Simulate a transaction to verify whether it will succeed before submitting it.

  • Debugging Inspect logMessages, computeUnitsConsumed, and err fields to debug failing transactions.

  • Estimate Compute Usage See how many compute units a transaction consumes before hitting the cap.

  • Program Development Quickly iterate on smart contracts without submitting on-chain transactions.

  • Validate Instruction Formatting Catch serialization or parameter errors before execution.


🧾 Request Parameters

[
  encodedTransaction: string,        // Required – base64-encoded signed transaction
  config?: {
    sigVerify?: boolean,             // Optional – verify signatures (default: false)
    commitment?: string,             // Optional – "processed", "confirmed", "finalized"
    replaceRecentBlockhash?: boolean,// Optional – use latest blockhash instead of original
    accounts?: {
      encoding?: string,             // Optional – "base64" | "base64+zstd" | "jsonParsed"
      addresses: string[]            // Optional – accounts to fetch data for during simulation
    },
    minContextSlot?: number          // Optional – minimum slot for simulation context
  }
]

Key Fields:

  • encodedTransaction: A fully signed transaction encoded in base64.

  • sigVerify: Whether to verify the transaction's signatures during simulation.

  • replaceRecentBlockhash: If true, substitutes the blockhash with the latest one (useful for testing older transactions).

  • accounts: Optionally return selected account data after simulation for inspection.

  • commitment: Level of commitment to simulate against. Typically "processed".


📦 Response Structure

{
  "context": {
    "slot": 221446650
  },
  "value": {
    "err": null,
    "logs": [
      "Program 11111111111111111111111111111111 invoke [1]",
      "Program returned success"
    ],
    "accounts": [],
    "unitsConsumed": 1420,
    "returnData": {
      "programId": "SomeProgramAddress",
      "data": ["encodedDataHere", "base64"]
    }
  }
}

Key Fields in value:

  • err: null if successful, or error details (e.g. InstructionError).

  • logs: An array of log messages emitted during simulation.

  • accounts: Optional account state if requested.

  • unitsConsumed: Compute units used during simulation.

  • returnData: Output returned from the transaction, if applicable.


🧪 Example

Simulate a Base64-Encoded Transaction

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "simulateTransaction",
  "params": [
    "Base64EncodedSignedTransactionHere",
    {
      "sigVerify": true,
      "commitment": "processed"
    }
  ]
}

Code Examples

const fetch = require('node-fetch');

async function simulateTransaction(rpcUrl) {
  try {
    const response = await fetch(rpcUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'simulateTransaction',
        "params": [
            "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEEjNmKiZGiOtSZ+g0//wH5kEQo3+UzictY+KlLV8hjXcs44M/Xnr+1SlZsqS6cFMQc46yj9PIsxqkycxJmXT+veJjIvefX4nhY9rY+B5qreeqTHu4mG6Xtxr5udn4MN8PnBt324e51j94YQl285GzN2rYa/E2DuQ0n/r35KNihi/zamQ6EeyeeVDvPVgUO2W3Lgt9hT+CfyqHvIa11egFPCgEDAwIBAAkDZAAAAAAAAAA=",
            {
              "commitment": "confirmed",
              "encoding": "base64",
              "replaceRecentBlockhash": true
            }
          ]
      }),
    });

    const data = await response.json();
    
    // Print the exact full response
    console.log('Full RPC Response:');
    console.log(JSON.stringify(data, null, 2));
    
    return data;
  } catch (error) {
    console.error('Error getting health:', error.message);
    return null;
  }
}

// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';

simulateTransaction(RPC_URL);

Example Response

{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "apiVersion": "2.3.3",
      "slot": 393226680
    },
    "value": {
      "accounts": null,
      "err": null,
      "innerInstructions": null,
      "loadedAccountsDataSize": 413,
      "logs": [
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]",
        "Program log: Instruction: Transfer",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 1714 of 200000 compute units",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success"
      ],
      "replacementBlockhash": {
        "blockhash": "6oFLsE7kmgJx9PjR4R63VRNtpAVJ648gCTr3nq5Hihit",
        "lastValidBlockHeight": 381186895
      },
      "returnData": null,
      "unitsConsumed": 1714
    }
  },
  "id": 1
}

💡 Developer Tips

  • Efficient Debugging Use simulateTransaction with "sigVerify": true for a full dry-run, including signature validation.

  • Catch Instruction Errors Failed deserialization, invalid accounts, or custom program errors will surface in err or logs.

  • Track Compute Units Helps optimize transaction size and complexity before submission.

  • Avoid Mainnet Transaction Waste Prevent failed transactions (and SOL loss from fees) by simulating first—especially in production environments.

  • returnData Support If your program uses sol_set_return_data, use this method to capture and inspect its output.


The simulateTransaction method is a powerful utility for Solana developers using CoinVera, enabling safe, cost-free validation and debugging of transaction logic—before committing anything to the chain.

Last updated