getTokenAccountBalance
Returns the token balance of an SPL Token account. Unlike getBalance which returns native SOL, this method returns the balance of a specific SPL token held in a token account. The response includes the raw amount, decimal count, and a human-readable UI amount. This is essential for any application displaying token balances, including wallets, portfolio trackers, and DeFi protocols.
Parameters
| # | Type | Required | Description |
|---|---|---|---|
| 1 | string | Yes | Base-58 encoded public key of the token account |
| 2 | object | No | Configuration object |
Configuration object fields:
| Field | Type | Description |
|---|---|---|
commitment | string | Commitment level: processed, confirmed, or finalized |
Response
Returns an RpcResponse object:
| Field | Type | Description |
|---|---|---|
context.slot | u64 | The slot at which the value was read |
value.amount | string | Raw balance as a string (to avoid precision loss) |
value.decimals | u8 | Number of base-10 digits to the right of the decimal |
value.uiAmount | `f64 | null` |
value.uiAmountString | string | Balance as a string, accounting for decimals |
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": "getTokenAccountBalance",
5 "params": [
6 "FYjTBVjknkzJXQMB2ZNKP8qNPCQzqe7uJ9Czz3VSmXo",
7 { "commitment": "confirmed" }
8 ]
9}'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: "getTokenAccountBalance",
8 params: [
9 "FYjTBVjknkzJXQMB2ZNKP8qNPCQzqe7uJ9Czz3VSmXo",
10 { commitment: "confirmed" }
11 ]
12 }),
13});
14const { result } = await response.json();
15console.log("Token balance:", result.value.uiAmountString);Python
1import requests
2
3response = requests.post("http://[IP_ADDRESS]:[PORT]", json={
4 "jsonrpc": "2.0",
5 "id": 1,
6 "method": "getTokenAccountBalance",
7 "params": [
8 "FYjTBVjknkzJXQMB2ZNKP8qNPCQzqe7uJ9Czz3VSmXo",
9 {"commitment": "confirmed"}
10 ]
11})
12result = response.json()["result"]
13print(f"Token balance: {result['value']['uiAmountString']}")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": "getTokenAccountBalance",
12 "params": [
13 "FYjTBVjknkzJXQMB2ZNKP8qNPCQzqe7uJ9Czz3VSmXo",
14 {"commitment": "confirmed"}
15 ]
16 }))
17 .send().await?
18 .text().await?;
19 println!("{}", res);
20 Ok(())
21}Example Response
1{
2 "jsonrpc": "2.0",
3 "result": {
4 "context": { "slot": 166974442 },
5 "value": {
6 "amount": "1000000000",
7 "decimals": 9,
8 "uiAmount": 1.0,
9 "uiAmountString": "1"
10 }
11 },
12 "id": 1
13}