Solana RPC API手册

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

getProgramAccounts

getProgramAccounts方法返回指定程序公钥拥有的全部账号。

请求参数

  • <string> - Pubkey of program, as base-58 encoded string
  • <object> - (optional) Configuration object containing the following optional fields:
    • (optional) Commitment
    • encoding: <string> - encoding for Account data, either "base58" (slow), "base64", "base64+zstd", or "jsonParsed". "base58" is limited to Account data of less than 129 bytes. "base64" will return base64 encoded data for Account data of any size. "base64+zstd" compresses the Account data using Zstandard and base64-encodes the result. "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 data field is type .
    • (optional) dataSlice: <object> - limit the returned account data using the provided offset: and length: fields; only available for "base58", "base64" or "base64+zstd" encodings.
    • (optional) filters: <array> - filter results using various filter objects; account must meet all filter criteria to be included in results
    • (optional) withContext: bool - wrap the result in an RpcResponse JSON object.

过滤器

  • memcmp: <object> - compares a provided series of bytes with program account data at a particular offset. Fields:
    • offset: <usize> - offset into program account data to start comparison
    • bytes: <string> - data to match, as base-58 encoded string and limited to less than 129 bytes
  • dataSize: <u64> - compares the program account data length with the provided data size

响应结果

By default the result field will be an array of JSON objects. If withContext flag is set the array will be wrapped in an RpcResponse JSON object.

The array will contain:

  • pubkey: <string> - the account Pubkey as base-58 encoded string
  • account: <object> - a JSON object, with the following sub fields:
    • 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":"getProgramAccounts", "params":["4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T"]}

响应:

{
  "jsonrpc": "2.0",
  "result": [
    {
      "account": {
        "data": "2R9jLfiAQ9bgdcw6h8s44439",
        "executable": false,
        "lamports": 15298080,
        "owner": "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
        "rentEpoch": 28
      },
      "pubkey": "CxELquR1gPP8wHe33gZ4QxqGB3sZ9RSwsJ2KshVewkFY"
    }
  ],
  "id": 1
}

请求:

curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getProgramAccounts",
    "params": [
      "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
      {
        "filters": [
          {
            "dataSize": 17
          },
          {
            "memcmp": {
              "offset": 4,
              "bytes": "3Mc6vR"
            }
          }
        ]
      }
    ]
  }

响应:

{
  "jsonrpc": "2.0",
  "result": [
    {
      "account": {
        "data": "2R9jLfiAQ9bgdcw6h8s44439",
        "executable": false,
        "lamports": 15298080,
        "owner": "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
        "rentEpoch": 28
      },
      "pubkey": "CxELquR1gPP8wHe33gZ4QxqGB3sZ9RSwsJ2KshVewkFY"
    }
  ],
  "id": 1
}