Check Token Balances
Learn how to check SOL and SPL token balances for any wallet
Check SOL or SPL token balances for any wallet address. The toolkit provides two main methods:
getBalance: Check balances for your own walletgetBalanceOther: Check balances for other wallets
Copy
// Check your SOL balance
const solBalance = await agent.methods.getBalance();
// Check your SPL token balance
const tokenBalance = await agent.methods.getBalance(
new PublicKey("token-mint-address")
);
// Check another wallet's SOL balance
const otherSolBalance = await agent.methods.getBalanceOther(
new PublicKey("wallet-address")
);
// Check another wallet's token balance
const otherTokenBalance = await agent.methods.getBalanceOther(
new PublicKey("wallet-address"),
new PublicKey("token-mint-address")
);tokenAddress
PublicKey
No
Token mint address (omit for SOL)
walletAddress
PublicKey
Yes
Wallet to check balance for
tokenAddress
PublicKey
No
Token mint address (omit for SOL)
Copy
For checking your own balance:
Copy
For checking other wallets:
Copy
Copy
Returns balances in UI units (e.g., SOL instead of lamports)
Handles non-existent token accounts gracefully
Supports all SPL tokens
Returns 0 for non-existent accounts
Copy
Error Handling
Handle non-existent accounts gracefully
Validate addresses before querying
Consider caching for frequent checks
Performance
Batch balance checks when possible
Consider using getMultipleAccounts
Cache results for short periods
UI Display
Format numbers appropriately
Show proper decimal places
Include token symbols
USDC:
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1vUSDT:
Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYBBONK:
DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263RAY:
4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6RSRM: `SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWR
Last updated