getTokenAccountBalance
Learn getTokenAccountBalance use cases, code examples, request parameters, response structure, and tips.
The getTokenAccountBalance RPC method in CoinVera returns the token balance of a specified SPL token account. It provides detailed information including raw amount, decimals, and user-friendly display formats.
✅ Common Use Cases
Display Token Balances in UI Show a user’s token balance for wallets and dApps.
Validate Token Holdings Confirm whether a wallet has a sufficient token balance before proceeding with transfers, swaps, or burns.
Bot/Automation Scripts Use in scripts to make decisions based on token balances (e.g., execute only if balance > threshold).
🧾 Request Parameters
account(string, required): The base-58 encoded address of the SPL token account to query.commitment(string, optional): Optional. Specifies the state commitment level—processed,confirmed, orfinalized.
📦 Response Structure
Returns a balance object under the value key:
{
"context": {
"slot": 221446650
},
"value": {
"amount": "1500000",
"decimals": 6,
"uiAmount": 1.5,
"uiAmountString": "1.5"
}
}amount: Raw token amount as a string (e.g. "1500000" for 1.5 tokens with 6 decimals).
decimals: Number of decimal places defined by the token mint.
uiAmount: The token amount as a number (floating point).
uiAmountString: The token amount as a formatted string.
🧪 Example
Query Balance of a Token Account
Request:
Code Examples
Response Example
💡 Developer Tips
Only Works on Token Accounts This method only accepts token account addresses, not general wallet addresses. Use
getTokenAccountsByOwnerfirst if needed.Lamports ≠ Token Amounts Unlike SOL balances, token balances vary in decimal precision—always respect the
decimalsvalue.String for Precision Use
uiAmountStringin UIs to avoid rounding errors, especially for large or small balances.Commitment Matters Add
commitment: "finalized"if you need the most reliable confirmed result.
The getTokenAccountBalance method is essential for tracking SPL token balances in real-time, especially in dApps, wallets, and trading bots built on CoinVera.
Last updated