Solana RPC API手册

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

simulateTransaction

Simulate sending a transaction

请求参数

  • <string> - Transaction, as an encoded string. The transaction must have a valid blockhash, but is not required to be signed.
  • <object> - (optional) Configuration object containing the following fields:
    • sigVerify: <bool> - if true the transaction signatures will be verified (default: false, conflicts with replaceRecentBlockhash)
    • commitment: <string> - (optional) Commitment level to simulate the transaction at (default: "finalized").
    • encoding: <string> - (optional) Encoding used for the transaction data. Either "base58" (slow, DEPRECATED), or "base64". (default: "base58").
    • replaceRecentBlockhash: <bool> - (optional) if true the transaction recent blockhash will be replaced with the most recent blockhash. (default: false, conflicts with sigVerify)
    • accounts: <object> - (optional) Accounts configuration object containing the following fields:
      • encoding: <string> - (optional) encoding for returned Account data, either "base64" (default), "base64+zstd" or "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 binary encoding, detectable when the data field is type .
      • addresses: <array> - An array of accounts to return, as base-58 encoded strings

响应结果

An RpcResponse containing a TransactionStatus object 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 {: }, 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

示例代码

请求:

curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "simulateTransaction",
    "params": [
      "4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaBCncVG7BFggS8w9snUts67BSh3EqKpXLUm5UMHfD7ZBe9GhARjbNQMLJ1QD3Spr6oMTBU6EhdB4RD8CP2xUxr2u3d6fos36PD98XS6oX8TQjLpsMwncs5DAMiD4nNnR8NBfyghGCWvCVifVwvA8B8TJxE1aiyiv2L429BCWfyzAme5sZW8rDb14NeCQHhZbtNqfXhcp2tAnaAT"
    ]
  }

响应:

{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "slot": 218
    },
    "value": {
      "err": null,
      "accounts": null,
      "logs": [
        "BPF program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri success"
      ]
    }
  },
  "id": 1
}