Skip to content

Latest commit

 

History

History
187 lines (147 loc) · 5.49 KB

simulateTransaction.mdx

File metadata and controls

187 lines (147 loc) · 5.49 KB
sidebarLabel title sidebarSortOrder hideTableOfContents altRoutes
simulateTransaction
simulateTransaction RPC Method
0
true
/docs/rpc/simulateTransaction

Simulate sending a transaction

Parameters

<Parameter type={"string"} required={true}>

Transaction, as an encoded string.

<Callout type={"info"}> The transaction must have a valid blockhash, but is not required to be signed.

<Parameter type={"object"} optional={true}>

Configuration object containing the following fields:

<Field name="commitment" type="string" defaultValue="finalized" optional={true} href="/docs/rpc/index.mdx#configuring-state-commitment"

Commitment level to simulate the transaction at

if `true` the transaction signatures will be verified (conflicts with `replaceRecentBlockhash`)

<Field name="replaceRecentBlockhash" type="bool" optional={true} defaultValue={false}

if true the transaction recent blockhash will be replaced with the most recent blockhash. (conflicts with sigVerify)

the minimum slot that the request can be evaluated at

Encoding used for the transaction data.

Values: base58 (slow, DEPRECATED), or base64.

<Field name="accounts" type={"object"} optional={true}>

Accounts configuration object containing the following fields:

An `array` of accounts to return, as base-58 encoded strings

encoding for returned Account data

<Values values={["base64", "base58", "base64+zstd", "jsonParsed"]} />

  • jsonParsed encoding attempts to use program-specific state parsers to return more human-readable and explicit account state data.
  • If jsonParsed is requested but a parser cannot be found, the field falls back to base64 encoding, detectable when the returned accounts.data field is type string.

Result

The result will be an RpcResponse JSON object with value set to a JSON object with the following fields:

  • err: <object|string|null> - Error if transaction failed, null if transaction succeeded. TransactionError definitions
  • logs: <array|null> - 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|null> - array of accounts with the same length as the accounts.addresses array in the request
    • <null> - if the account doesn't exist or if err is not null
    • <object> - otherwise, a JSON object containing:
      • lamports: <u64> - number of lamports assigned to this account, as a u64
      • owner: <string> - base-58 encoded Pubkey of the program this account has been assigned to
      • data: <[string, encoding]|object> - data associated with the account, either as encoded binary data or JSON format {<program>: <state>} - depending on encoding parameter
      • executable: <bool> - boolean indicating if the account contains a program (and is strictly read-only)
      • rentEpoch: <u64> - the epoch at which this account will next owe rent, as u64
  • unitsConsumed: <u64|undefined> - The number of compute budget units consumed during the processing of this transaction
  • returnData: <object|null> - the most-recent return data generated by an instruction in the transaction, with the following fields:
    • programId: <string> - the program that generated the return data, as base-58 encoded Pubkey
    • data: <[string, encoding]> - the return data itself, as base-64 encoded binary data

Code sample

curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "simulateTransaction",
    "params": [
      "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDArczbMia1tLmq7zz4DinMNN0pJ1JtLdqIJPUw3YrGCzYAMHBsgN27lcgB6H2WQvFgyZuJYHa46puOQo9yQ8CVQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp20C7Wj2aiuk5TReAXo+VTVg8QTHjs0UjNMMKCvpzZ+ABAgEBARU=",
      {
        "encoding":"base64",
      }
    ]
  }
'

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
}