区块链中文技术社区

Solana RPC 方法的常见 JSON 数据结构

各种 Solana RPC 方法将返回更复杂的响应作为结构化 JSON 对象,并填充特定的键值。
这些 JSON 数据结构中最常见的包括:

交易

交易与其他区块链上的交易截然不同。请务必查看交易剖析以了解 Solana 上的交易。

JSON

交易的JSON结构定义如下:

"transaction": {
  "message": {
    "accountKeys": [
      "EF3cbGuhJus5mCdGZkVz7GQce7QHbswBhZu6fmK9zkCR",
      "4LAyP5B5jNyNm7Ar2dG8sNipEiwTMEyCHd1iCHhhXYkY",
      "11111111111111111111111111111111"
    ],
    "header": {
      "numReadonlySignedAccounts": 0,
      "numReadonlyUnsignedAccounts": 1,
      "numRequiredSignatures": 1
    },
    "instructions": [
      {
        "accounts": [
          0,
          1
        ],
        "data": "3Bxs411Dtc7pkFQj",
        "programIdIndex": 2,
        "stackHeight": null
      }
    ],
    "recentBlockhash": "6pw7JBwq9tb5GHiBQgVY6RAp5otbouwYvEc1kbbxKFec"
  },
  "signatures": [
    "2M8mvwhtxyz3vAokXESVeR9FQ4t9QQxF5ek6ENNBBHVkW5XyZvJVK5MQej5ccwTZH6iWBJJoZ2CcizBs89pvpPBh"
  ]
}

JSON 解析

交易的 JSON 解析结构遵循与常规 JSON 格式类似的结构,并附加了帐户和指令信息的解析:

"transaction": {
  "message": {
    "accountKeys": [
      {
        "pubkey": "EF3cbGuhJus5mCdGZkVz7GQce7QHbswBhZu6fmK9zkCR",
        "signer": true,
        "source": "transaction",
        "writable": true
      },
      {
        "pubkey": "4LAyP5B5jNyNm7Ar2dG8sNipEiwTMEyCHd1iCHhhXYkY",
        "signer": false,
        "source": "transaction",
        "writable": true
      },
      {
        "pubkey": "11111111111111111111111111111111",
        "signer": false,
        "source": "transaction",
        "writable": false
      }
    ],
    "instructions": [
      {
        "parsed": {
          "info": {
            "destination": "4LAyP5B5jNyNm7Ar2dG8sNipEiwTMEyCHd1iCHhhXYkY",
            "lamports": 100000000,
            "source": "EF3cbGuhJus5mCdGZkVz7GQce7QHbswBhZu6fmK9zkCR"
          },
          "type": "transfer"
        },
        "program": "system",
        "programId": "11111111111111111111111111111111",
        "stackHeight": null
      }
    ],
    "recentBlockhash": "6pw7JBwq9tb5GHiBQgVY6RAp5otbouwYvEc1kbbxKFec"
  },
  "signatures": [
    "2M8mvwhtxyz3vAokXESVeR9FQ4t9QQxF5ek6ENNBBHVkW5XyZvJVK5MQej5ccwTZH6iWBJJoZ2CcizBs89pvpPBh"
  ]
}

交易状态元数据

{
  "meta": {
    "err": null,
    "fee": 5000,
    "innerInstructions": [],
    "logMessages": [],
    "postBalances": [499998932500, 26858640, 1, 1, 1],
    "postTokenBalances": [],
    "preBalances": [499998937500, 26858640, 1, 1, 1],
    "preTokenBalances": [],
    "rewards": null,
    "status": {
      "Ok": null
    }
  }
}

内部指示

Solana 运行时记录在交易处理期间调用的跨程序指令,并使这些指令可用,从而提高每个交易指令在链上执行内容的透明度。调用的指令按原始交易指令分组,并按处理顺序列出。

内部指令的 JSON 结构定义为以下结构的对象列表

"innerInstructions": [
  {
    "index": 0,
    "instructions": [
      {
        "accounts": [
          0,
          1,
          2
        ],
        "data": "WPNHsFPyEMr",
        "programIdIndex": 3,
        "stackHeight": 2
      },
      {
        "accounts": [
          0,
          1
        ],
        "data": "11111dBUPbGETd4QtNMQVg8HqgcZtKy6DcJm6R4TZufJkuhkDS47VsauCCGhLf2xrm5BQ",
        "programIdIndex": 2,
        "stackHeight": 3
      }
    ]
  }
]

参考交易:

"transaction": {
  "message": {
    "accountKeys": [
      "4kh6HxYZiAebF8HWLsUWod2EaQQ6iWHpHYCz8UcmFbM1",
      "Bpo7aaM9kqfCjM6JgZCSdev7HsaUFj51mBPPEhQcDpUR",
      "11111111111111111111111111111111",
      "8HupNBr7SBhBLcBsLhbtes3tCarBm6Bvpqp5AfVjHuj8",
      "GENmb1D59wqCKRwujq4PJ8461EccQ5srLHrXyXp4HMTH"
    ],
    "header": {
      "numReadonlySignedAccounts": 0,
      "numReadonlyUnsignedAccounts": 3,
      "numRequiredSignatures": 2
    },
    "instructions": [
      {
        "accounts": [
          0,
          1,
          2,
          3
        ],
        "data": "H2ot5wbZsmL",
        "programIdIndex": 4,
        "stackHeight": null
      }
    ],
    "recentBlockhash": "28CroH2jyCaCFF6ssyUK989zBZY6dBxnUNU9A4oPUbER"
  },
  "signatures": [
    "4i4EuRQ1sNzKWEBYwg28VAMkQbaAeHyRRwu1tQRksowtQhGRJtgaHXpDAhBfpYZnVodGoQYwiUiB5yBRDoWbZ7VH",
    "2dipFcFF4CvwtbCFbRdctQmyzAYcq8RWrLryZErbKPhnriCJ6wDmKfJoSJfDjFNzUEcJDKkfasS2pcjvGEUjdYN6"
  ]
}

代币余额

"postTokenBalances": [
  {
    "accountIndex": 1,
    "mint": "6HvU8PbqP3nZLkFF59rr2zkTHqetPLgb6NnxKZLHQxNp",
    "owner": "DKypunNAGLPGBj3SocY8fF4ZrnDNVTf6QcUyW4trvkB",
    "programId": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
    "uiTokenAmount": {
      "amount": "0",
      "decimals": 2,
      "uiAmount": null,
      "uiAmountString": "0"
    }
  },
  {
    "accountIndex": 2,
    "mint": "6HvU8PbqP3nZLkFF59rr2zkTHqetPLgb6NnxKZLHQxNp",
    "owner": "8xm9beCpBH7SgqRz1mKua7KJF52whAVCiDEV1qREGHNV",
    "programId": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
    "uiTokenAmount": {
      "amount": "100",
      "decimals": 2,
      "uiAmount": 1.0,
      "uiAmountString": "1"
    }
  }
],

"preTokenBalances": [
  {
    "accountIndex": 1,
    "mint": "6HvU8PbqP3nZLkFF59rr2zkTHqetPLgb6NnxKZLHQxNp",
    "owner": "DKypunNAGLPGBj3SocY8fF4ZrnDNVTf6QcUyW4trvkB",
    "programId": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
    "uiTokenAmount": {
      "amount": "100",
      "decimals": 2,
      "uiAmount": 1.0,
      "uiAmountString": "1"
    }
  },
  {
    "accountIndex": 2,
    "mint": "6HvU8PbqP3nZLkFF59rr2zkTHqetPLgb6NnxKZLHQxNp",
    "owner": "8xm9beCpBH7SgqRz1mKua7KJF52whAVCiDEV1qREGHNV",
    "programId": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
    "uiTokenAmount": {
      "amount": "0",
      "decimals": 2,
      "uiAmount": null,
      "uiAmountString": "0"
    }
  }
]

参考交易:

"transaction": {
  "message": {
    "accountKeys": [
      {
        "pubkey": "DKypunNAGLPGBj3SocY8fF4ZrnDNVTf6QcUyW4trvkB",
        "signer": true,
        "source": "transaction",
        "writable": true
      },
      {
        "pubkey": "39nzuQ2WYHf231DJRPt1TLfaXSWXEKYGcqP3NQf6zK7G",
        "signer": false,
        "source": "transaction",
        "writable": true
      },
      {
        "pubkey": "DtCPWGmvCTov7CNmNTx8AFe3SEFSxgy265kZawv8SVL3",
        "signer": false,
        "source": "transaction",
        "writable": true
      },
      {
        "pubkey": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
        "signer": false,
        "source": "transaction",
        "writable": false
      }
    ],
    "addressTableLookups": [],
    "instructions": [
      {
        "parsed": {
          "info": {
            "amount": "100",
            "authority": "DKypunNAGLPGBj3SocY8fF4ZrnDNVTf6QcUyW4trvkB",
            "destination": "DtCPWGmvCTov7CNmNTx8AFe3SEFSxgy265kZawv8SVL3",
            "source": "39nzuQ2WYHf231DJRPt1TLfaXSWXEKYGcqP3NQf6zK7G"
          },
          "type": "transfer"
        },
        "program": "spl-token",
        "programId": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
        "stackHeight": null
      }
    ],
    "recentBlockhash": "42mjf871LtzDK8NVZUAht1xBoCvNMagQGSM7BnFWZD6M"
  },
  "signatures": [
    "5ZQqsF4tTFJDR5vuNJxejtw2GMc8KEtnPXnQjwhGzAtdbPTKtrLfPkFAbBTyPjZSVB3CbR5BiP5S8zAfZNtuwh88"
  ]
}

代币余额的 JSON 结构定义为以下结构的对象列表:

原文:https://solana.com/zh/docs/rpc/json-structures

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »