getTokenAccountsByOwner
Returns all SPL Token accounts by token owner.
请求参数
<string>
- Pubkey of account owner 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
- mint:
<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
- lamports:
示例代码
请求:
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0",
"id": 1,
"method": "getTokenAccountsByOwner",
"params": [
"4Qkev8aNZcqFNSRhQzwyLMFSsi94jHqE8WNVTJzTP99F",
{
"mint": "3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E"
},
{
"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": null,
"delegatedAmount": 1,
"isInitialized": true,
"isNative": false,
"mint": "3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E",
"owner": "4Qkev8aNZcqFNSRhQzwyLMFSsi94jHqE8WNVTJzTP99F"
}
}
},
"executable": false,
"lamports": 1726080,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 4
}
]
},
"id": 1
}