getTokenAccountsByOwner
Returns all SPL Token accounts by token owner.

Parameters

  • <base-58 encoded string> - Pubkey of queried SPL token account owner
  • <object> - Either:
    • mint: <base-58 encoded string> - Pubkey of the specific token Mint to limit accounts to
    OR
    • programId:<base-58 encoded string> - Pubkey of the Token program that owns the accounts
  • <object> - (optional) Config object:
    • commitment: (optional) Configures the commitment level of the blocks queried Accepts one of the following strings: ["finalized", "confirmed", "processed"] For more info, refer to this doc.
    • encoding: (optional) <string> - data encoding for each returned transaction
      Accepts one of the following strings: ["json" (Default), "jsonParsed", "base58" (slow), "base64"] "jsonParsed" encoding attempts to use program-specific parsers to make the transaction.message.instructions list more human-readable; if a parser cannot be found, the instruction falls back to default JSON.
    • dataSlice: (optional) <object> - limits the returned account data using the provided offset: <usize> and length: <usize> fields; only available for "base58", "base64" or "base64+zstd" encodings.
    • minContextSlot: (optional) <number> - sets the minimum slot that the request can be evaluated at.

Results

  • pubkey: <base-58 encoded string> - the account Pubkey
  • account: <object> - a JSON object, with the following sub fields:
    • lamports: <u64>, number of lamports assigned to this account
    • owner:<base-58 encoded string>, 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 {<program>: <state>}
    • 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

Example

Request

cURL
1
curl --location --request POST 'https://solana-mainnet.g.alchemy.com/v2/alch-demo/' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"method": "getTokenAccountsByOwner",
5
"id": 1,
6
"jsonrpc": "2.0",
7
"params": [
8
"J27ma1MPBRvmPJxLqBqQGNECMXDm9L6abFa4duKiPosa",
9
{
10
"mint": "2FPyTwcZLUg1MDrwsyoP4D6s1tM7hAkHYRjkNb5w6Pxk"
11
},
12
{
13
"encoding": "jsonParsed"
14
}
15
]
16
}'
Copied!

Response

1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"context": {
5
"slot": 137568828
6
},
7
"value": [
8
{
9
"account": {
10
"data": {
11
"parsed": {
12
"info": {
13
"isNative": false,
14
"mint": "2FPyTwcZLUg1MDrwsyoP4D6s1tM7hAkHYRjkNb5w6Pxk",
15
"owner": "J27ma1MPBRvmPJxLqBqQGNECMXDm9L6abFa4duKiPosa",
16
"state": "initialized",
17
"tokenAmount": {
18
"amount": "821",
19
"decimals": 6,
20
"uiAmount": 8.21E-4,
21
"uiAmountString": "0.000821"
22
}
23
},
24
"type": "account"
25
},
26
"program": "spl-token",
27
"space": 165
28
},
29
"executable": false,
30
"lamports": 2039280,
31
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
32
"rentEpoch": 318
33
},
34
"pubkey": "Exo9AH6fNchE43GaJB85FT7ToYiuKnKzYDyW5mFeTXRR"
35
}
36
]
37
},
38
"id": 1
39
}
Copied!