githubEdit

simulateTransaction – Solana

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

circle-check

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

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

cURL Example

Response

A successful request returns the simulation results.

simulateTransaction Example Response

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

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

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

Was this helpful?