Solana RPC API手册

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

getTokenAccountsByDelegate

Returns all SPL Token accounts by approved Delegate.

请求参数

  • <string> - Pubkey of account delegate to query, as base-58 encoded string
  • <object> - Either:
    • mint: <string> - Pubkey of the specific token Mint to limit accounts to, as base-58 encoded string; or
    • programId: <string> - Pubkey of the Token program ID that owns the accounts, 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". "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 valid mint cannot be found for a particular account, that account will be filtered out from results.
    • (optional) dataSlice: <object> - limit the returned account data using the provided offset: and length: fields; only available for "base58", "base64" or "base64+zstd" encodings.

响应结果

The result will be an RpcResponse JSON object with value equal to an array of JSON objects, which 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: <object>, Token state data associated with the account, either as encoded binary data or in JSON format {: }
    • 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": "getTokenAccountsByDelegate",
    "params": [
      "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
      {
        "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
      },
      {
        "encoding": "jsonParsed"
      }
    ]
  }

响应:

{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "slot": 1114
    },
    "value": [
      {
        "data": {
          "program": "spl-token",
          "parsed": {
            "accountType": "account",
            "info": {
              "tokenAmount": {
                "amount": "1",
                "decimals": 1,
                "uiAmount": 0.1,
                "uiAmountString": "0.1",
              },
              "delegate": "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
              "delegatedAmount": 1,
              "isInitialized": true,
              "isNative": false,
              "mint": "3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E",
              "owner": "CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD"
            }
          }
        },
        "executable": false,
        "lamports": 1726080,
        "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "rentEpoch": 4
      }
    ]
  },
  "id": 1
}