getTokenAccountsByOwner
Returns all SPL Token accounts owned by a specified address. This is the standard method for loading a user's complete token portfolio -- it returns every token account the user owns, optionally filtered by mint or token program. Wallets, portfolio trackers, and DeFi applications use this extensively to display token holdings, and it supports the jsonParsed encoding for human-readable token data.
Parameters
| # | Type | Required | Description |
|---|---|---|---|
| 1 | string | Yes | Base-58 encoded public key of the account owner |
| 2 | object | Yes | Filter object -- must contain either mint or programId |
| 3 | object | No | Configuration object |
Configuration object fields:
| Field | Type | Description |
|---|---|---|
mint | string | Filter by SPL Token mint address (base-58) |
programId | string | Filter by SPL Token program ID (base-58) |
encoding | string | Data encoding: base64, base64+zstd, or jsonParsed |
commitment | string | Commitment level: processed, confirmed, or finalized |
dataSlice | object | Limit returned data: { offset: number, length: number } |
minContextSlot | number | Minimum slot at which the request can be evaluated |
Response
Returns an RpcResponse with an array of token account objects:
| Field | Type | Description |
|---|---|---|
context.slot | u64 | The slot at which the value was read |
value[].pubkey | string | Token account address (base-58) |
value[].account.data | object | Token account data in the requested encoding |
value[].account.lamports | u64 | Lamports in the token account |
value[].account.owner | string | Token program ID |
Code Examples
cURL
1curl http://[IP_ADDRESS]:[PORT] -X POST -H "Content-Type: application/json" -d '{
2 "jsonrpc": "2.0",
3 "id": 1,
4 "method": "getTokenAccountsByOwner",
5 "params": [
6 "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg",
7 { "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
8 { "encoding": "jsonParsed" }
9 ]
10}'TypeScript
1const response = await fetch("http://[IP_ADDRESS]:[PORT]", {
2 method: "POST",
3 headers: { "Content-Type": "application/json" },
4 body: JSON.stringify({
5 jsonrpc: "2.0",
6 id: 1,
7 method: "getTokenAccountsByOwner",
8 params: [
9 "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg",
10 { programId: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
11 { encoding: "jsonParsed" }
12 ]
13 }),
14});
15const { result } = await response.json();
16console.log("Token accounts:", result.value.length);Python
1import requests
2
3response = requests.post("http://[IP_ADDRESS]:[PORT]", json={
4 "jsonrpc": "2.0",
5 "id": 1,
6 "method": "getTokenAccountsByOwner",
7 "params": [
8 "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg",
9 {"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},
10 {"encoding": "jsonParsed"}
11 ]
12})
13result = response.json()["result"]
14print(f"Token accounts: {len(result['value'])}")Rust
1use reqwest::Client;
2use serde_json::json;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let client = Client::new();
7 let res = client.post("http://[IP_ADDRESS]:[PORT]")
8 .json(&json!({
9 "jsonrpc": "2.0",
10 "id": 1,
11 "method": "getTokenAccountsByOwner",
12 "params": [
13 "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg",
14 {"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},
15 {"encoding": "jsonParsed"}
16 ]
17 }))
18 .send().await?
19 .text().await?;
20 println!("{}", res);
21 Ok(())
22}Example Response
1{
2 "jsonrpc": "2.0",
3 "result": {
4 "context": { "slot": 166974442 },
5 "value": [
6 {
7 "pubkey": "CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD",
8 "account": {
9 "data": { "parsed": { "type": "account", "info": { "tokenAmount": { "amount": "1000000", "decimals": 6, "uiAmount": 1.0 } } }, "program": "spl-token", "space": 165 },
10 "executable": false,
11 "lamports": 2039280,
12 "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
13 }
14 }
15 ]
16 },
17 "id": 1
18}