getTokenAccountsByOwner — Solana RPC Method
getTokenAccountsByOwner returns all SPL Token accounts owned by a wallet, optionally filtered by a specific mint or token program. This is the standard method for fetching a wallet’s token portfolio.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
owner | string | Yes | Base-58 encoded wallet public key. |
mint | string | No | Filter by specific token mint. Provide either mint or programId, not both. |
programId | string | No | Filter by token program. Use for SPL Token or Token-2022. |
commitment | string | No | processed, confirmed, or finalized. Default: finalized. |
encoding | string | No | base64 or jsonParsed. Default: base64. |
dataSlice | object | No | {offset: usize, length: usize}. Not available with jsonParsed. |
minContextSlot | number | No | Minimum slot at which the request can be evaluated. |
You must provide either mint or programId as a filter.
Request
curl -X POST https://api.mainnet-beta.solana.com \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getTokenAccountsByOwner",
"params": [
"vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg",
{"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},
{"encoding": "jsonParsed"}
]
}'
TypeScript (@solana/kit)
import { createSolanaRpc, address } from "@solana/kit";
const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
const tokenAccounts = await rpc
.getTokenAccountsByOwner(
address("vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg"),
{ programId: address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") },
{ encoding: "jsonParsed" }
)
.send();
for (const { account } of tokenAccounts.value) {
const parsed = (account.data as any).parsed.info;
console.log(`Mint: ${parsed.mint}, Balance: ${parsed.tokenAmount.uiAmountString}`);
}
Response
{
"jsonrpc": "2.0",
"result": {
"context": { "slot": 341200000, "apiVersion": "2.2.4" },
"value": [
{
"pubkey": "C2gJg6tKpQs41PRS1nC8aw3ZKNZK3HQQZGVrDFDup5nx",
"account": {
"data": {
"program": "spl-token",
"parsed": {
"type": "account",
"info": {
"mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"owner": "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg",
"tokenAmount": {
"amount": "5000000",
"decimals": 6,
"uiAmount": 5.0,
"uiAmountString": "5"
},
"state": "initialized"
}
},
"space": 165
},
"executable": false,
"lamports": 2039280,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 18446744073709551615,
"space": 165
}
}
]
},
"id": 1
}
Common errors
- Must provide mint or programId — omitting both filters returns an error.
- Cannot provide both — passing both
mintandprogramIdreturns an error.
Performance
Active wallets may hold hundreds of token accounts. Use the mint filter when you only need a specific token’s balance. The jsonParsed encoding adds server-side parsing overhead but saves client-side deserialization.
FAQ
How do I get all tokens a wallet holds?
Call with programId set to the SPL Token program (TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA) and encoding: "jsonParsed". For Token-2022 tokens, also query with the Token-2022 program ID.
Does this include zero-balance accounts? Yes. Token accounts with a zero balance but that have not been closed still appear in the results. Filter them client-side if needed.
How do I find a specific token balance?
Use the mint filter with the token’s mint address. This returns only the token account(s) for that specific token.
Can a wallet have multiple accounts for the same token? Yes. A wallet can own multiple token accounts for the same mint, though typically only one is the Associated Token Account (ATA). The others may be created manually for specific use cases.
How do I include Token-2022 tokens?
Make a second call with programId set to TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb. Or make two calls — one for each program — and merge the results.
Parameters
| Parameter | Type | Required | Description | Default |
|---|---|---|---|---|
owner | string | Yes | Base-58 encoded public key of the account owner. | — |
mint | string | No | Filter by token mint address. | — |
programId | string | No | Filter by token program ID. | — |
commitment | string | No | Commitment level: processed, confirmed, or finalized. | finalized |
encoding | string | No | Data encoding: base64, jsonParsed. | base64 |
dataSlice | object | No | Limit returned data: {offset: usize, length: usize}. Not available with jsonParsed. | — |
minContextSlot | number | No | Minimum slot at which the request can be evaluated. | — |
Updated: