getTokenAccountBalance
https://api.triport.io/v1/solReturns the token balance of a single SPL Token account.
getTokenAccountBalance returns the balance held by one SPL Token account:
the raw integer amount, the token's decimals, and the human-readable
uiAmount / uiAmountString already scaled by those decimals.
The pubkey you pass must be the address of a token account — not the
wallet that owns it, and not the token mint. A token account is the per-mint
holding account derived for an owner (commonly the associated token account).
Passing a wallet or a mint address yields an invalid-params error rather than a
balance. To go from a wallet to its token accounts, resolve them first with
getTokenAccountsByOwner, then call this method on the resulting account
addresses.
The balance is reported relative to a particular slot, returned in the
context object. Use the optional commitment config to control how finalized
that slot must be, and minContextSlot to require the node has reached at least
a given slot before serving the request.
Parameters
JSON-RPC params is a positional array: [pubkey, config?].
pubkeystring (base-58)required^[1-9A-HJ-NP-Za-km-z]{32,44}$.configobjectoptionalcommitmentstringoptionalprocessed, confirmed, or finalized.minContextSlotintegeroptionalResponse
The example above reads a token account holding 9864 base units of a 2-decimal
token, i.e. 98.64 tokens.
resultobjectTokenBalanceResponse envelope.result.contextobjectresult.context.slotintegerresult.context.apiVersionstringresult.valueobjectTokenAmount).result.value.amountstringu64 precision.result.value.decimalsintegerresult.value.uiAmountnumberdecimals, as a JSON number. May lose precision for very large balances — prefer uiAmountString.result.value.uiAmountStringstringdecimals, as a string. The precision-safe field to display.Errors
Errors are returned in the standard JSON-RPC error envelope. See the shared errors reference for the full envelope shape and shared codes.
| Code | Meaning | When it happens |
|---|---|---|
-32602 | Invalid params | pubkey is missing, not valid base-58, or is not an SPL Token account (e.g. a wallet or mint was passed), or config is malformed. |
401 | Unauthorized | Missing or invalid Authorization: Bearer key. |
429 | Rate limited | More than your tier's RPS for sol_read_rpc (20 / 60 / 200 / 600). |
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/sol", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "getTokenAccountBalance",
params: ["7fUAJdStEuGbc3sM84cKRL6yYaaSstyLSU4ve5oovLS7"],
}),
});
const { result } = await res.json();
console.log(`Balance: ${result.value.uiAmountString} (slot ${result.context.slot})`);TypeScript SDK (@triport/sdk)
import { TriportClient } from "@triport/sdk";
const client = new TriportClient({ apiKey: process.env.TRIPORT_API_KEY });
const { context, value } = await client.solana.getTokenAccountBalance(
"7fUAJdStEuGbc3sM84cKRL6yYaaSstyLSU4ve5oovLS7",
{ commitment: "finalized" }
);
console.log(`Balance: ${value.uiAmountString} (slot ${context.slot})`);Python (triport-sdk)
import os
from triport import TriportClient
client = TriportClient(api_key=os.environ["TRIPORT_API_KEY"])
result = client.solana.get_token_account_balance(
"7fUAJdStEuGbc3sM84cKRL6yYaaSstyLSU4ve5oovLS7",
commitment="finalized",
)
value = result["value"]
print(f"Balance: {value['uiAmountString']} (slot {result['context']['slot']})")Notes
- Token account, not wallet or mint: the most common mistake is passing a
wallet address. Resolve a wallet's holdings with
getTokenAccountsByOwnerfirst, then query each returned account here. - Use
amountfor math,uiAmountStringfor display:amountis the exactu64base-unit count (string to avoid precision loss);uiAmountStringappliesdecimalssafely. Avoid the floating-pointuiAmountfor accounting. - Closed or non-existent accounts: querying an address that is not a live token account returns an invalid-params error rather than a zero balance.
- Commitment defaults: when
commitmentis omitted, the node's default commitment applies. Passfinalizedfor the strongest consistency guarantee. - Related methods:
getTokenAccountsByOwnerandgetTokenAccountsByDelegateenumerate token accounts;getAccountInforeturns the full parsed account data.