getBalance
: Check balances for your own walletgetBalanceOther
: Check balances for other wallets
Usage
Parameters
getBalance
Parameter | Type | Required | Description |
---|---|---|---|
tokenAddress | PublicKey | No | Token mint address (omit for SOL) |
getBalanceOther
Parameter | Type | Required | Description |
---|---|---|---|
walletAddress | PublicKey | Yes | Wallet to check balance for |
tokenAddress | PublicKey | No | Token mint address (omit for SOL) |
Example Prompts
Natural Language Prompts
LangChain Tool Prompts
For checking your own balance:Example Implementation
Implementation Details
- 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
Error Handling
Best Practices
-
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
Common Token Addresses
- USDC:
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
- USDT:
Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB
- BONK:
DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263
- RAY:
4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R
- SRM: `SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWR