simulateTransaction - Stellar

Example code for the simulateTransaction JSON-RPC method. Complete guide on how to use simulateTransaction JSON-RPC in GetBlock Web3 documentation.

This method simulates a smart contract invocation without actually submitting it to the network. It's useful for testing and debugging transactions safely.

Parameters

Parameter
Type
Description

transaction

string

Transaction envelope (base64-encoded XDR)

resourceConfig

object

(optional) Resource configuration

Resource Config Object:

Field
Type
Description

instructionLeeway

integer

Additional instructions buffer

Request

curl
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "simulateTransaction",
    "params": {
        "transaction": "AAAAAgAAAAAg4dbAxsGAGICfBG3iT2cKGYQ6hK4sJWzZ6or1C5v6GAAAAGQAJsOiAAAAEQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABzAP+dP0PsNzYvFF1pv7a8RQXwH5eg3uZBbbWjE9PwAsAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAACDh1sDGwYAYgJ8EbeJPZwoZhDqEriwlbNnqivULm/oYAAAAAwAAAAMAAAAAAAAAAAAAAAA=",
        "resourceConfig": {
            "instructionLeeway": 3000000
        }
    },
    "id": "getblock.io"
}'

Response

Response Parameters

Field
Type
Description

latestLedger

integer

Latest ledger at simulation time

minResourceFee

string

Recommended minimum resource fee

results

array

Simulation results for each operation

transactionData

string

Recommended Soroban transaction data (base64 XDR)

cost

object

Resource cost breakdown

cpuInsns

string

CPU instructions consumed

memBytes

string

Memory bytes consumed

error

string

(optional) Error message if simulation failed

Use Case

The simulateTransaction method is essential for:

  • Smart contract testing before submission

  • Fee estimation for Soroban transactions

  • Transaction debugging

  • Dry-run operations

  • Resource requirement calculation

  • Authorization preparation

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid ACCESS-TOKEN

-32602

Invalid params

Invalid transaction format

Simulation error

Various

Contract execution failure

Last updated

Was this helpful?