Tokens
getTokenAccountBalance
Returns the token balance of an account
Parameters
Public key of the token account (base-58 encoded)
Configuration object containing:
Commitment level (processed, confirmed, finalized)
Response
Object containing:
Code Examples
Basic Request
Using web3.js
Notes
- Returns the token balance of a token account
- The balance is returned in both raw and UI-friendly formats
- The response is immediate as it reads from the current state
- The balance can change with token transfers and other operations
- The account must be a valid token account
Best Practices
- Use appropriate commitment level based on your needs
- Cache results when appropriate to reduce RPC load
- Monitor for changes in token balances
- Consider using websocket subscription for real-time updates
- Handle network errors and retry when appropriate
Common Errors
Code | Message | Solution |
---|---|---|
-32601 | Method not found | Verify you’re connected to a Solana RPC node |
-32602 | Invalid params | Check token account public key |
-32007 | Token account not found | Verify the token account exists |
-32008 | Invalid token account | Verify the account is a valid token account |
Use Cases
-
Token Balance Analysis
-
Token Balance Monitoring
-
Token Balance Planning