Documentation index

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

#TypeRequiredDescription
1stringYesBase-58 encoded public key of the token account
2objectNoConfiguration object

Configuration object fields:

FieldTypeDescription
commitmentstringCommitment level: processed, confirmed, or finalized

Response

Returns an RpcResponse object:

FieldTypeDescription
context.slotu64The slot at which the value was read
value.amountstringRaw balance as a string (to avoid precision loss)
value.decimalsu8Number of base-10 digits to the right of the decimal
value.uiAmount`f64null`
value.uiAmountStringstringBalance as a string, accounting for decimals

Code Examples

cURL

Terminal
curl http://88.216.36.108:7999 -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getTokenAccountBalance",
  "params": [
    "FYjTBVjknkzJXQMB2ZNKP8qNPCQzqe7uJ9Czz3VSmXo",
    { "commitment": "confirmed" }
  ]
}'

TypeScript

TypeScript
const response = await fetch("http://88.216.36.108:7999", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "getTokenAccountBalance",
    params: [
      "FYjTBVjknkzJXQMB2ZNKP8qNPCQzqe7uJ9Czz3VSmXo",
      { commitment: "confirmed" }
    ]
  }),
});
const { result } = await response.json();
console.log("Token balance:", result.value.uiAmountString);

Python

Python
import requests

response = requests.post("http://88.216.36.108:7999", json={
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getTokenAccountBalance",
    "params": [
        "FYjTBVjknkzJXQMB2ZNKP8qNPCQzqe7uJ9Czz3VSmXo",
        {"commitment": "confirmed"}
    ]
})
result = response.json()["result"]
print(f"Token balance: {result['value']['uiAmountString']}")

Rust

Rust
use reqwest::Client;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let res = client.post("http://88.216.36.108:7999")
        .json(&json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getTokenAccountBalance",
            "params": [
                "FYjTBVjknkzJXQMB2ZNKP8qNPCQzqe7uJ9Czz3VSmXo",
                {"commitment": "confirmed"}
            ]
        }))
        .send().await?
        .text().await?;
    println!("{}", res);
    Ok(())
}

Example Response

JSON
{
  "jsonrpc": "2.0",
  "result": {
    "context": { "slot": 166974442 },
    "value": {
      "amount": "1000000000",
      "decimals": 9,
      "uiAmount": 1.0,
      "uiAmountString": "1"
    }
  },
  "id": 1
}