get_token_balance
Retrieve SPL token balances for specific wallets on the Solana blockchain by providing wallet names and token mint addresses.
Instructions
Get SPL token balance for a wallet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| walletName | Yes | Name of the wallet | |
| tokenMint | Yes | Token mint address |
Implementation Reference
- src/index.ts:605-634 (handler)The handler function that implements the get_token_balance tool logic: retrieves the wallet, computes the associated token account for the given mint, fetches the account info, and returns the balance or handles errors.async function handleGetTokenBalance(args: any) { const { walletName, tokenMint } = args; const wallet = wallets.get(walletName); if (!wallet) { throw new Error(`Wallet '${walletName}' not found`); } ensureConnection(); try { const tokenMintPubkey = new PublicKey(tokenMint); const tokenAccount = await getAssociatedTokenAddress(tokenMintPubkey, wallet.keypair.publicKey); const accountInfo = await getAccount(connection, tokenAccount); return { wallet: walletName, tokenMint: tokenMint, balance: accountInfo.amount.toString(), decimals: accountInfo.mint.toString() }; } catch (error) { return { wallet: walletName, tokenMint: tokenMint, balance: "0", error: "Token account not found or error retrieving balance" }; } }
- src/index.ts:131-144 (schema)Input schema defining the parameters for the get_token_balance tool: walletName (string) and tokenMint (string), both required.inputSchema: { type: "object", properties: { walletName: { type: "string", description: "Name of the wallet" }, tokenMint: { type: "string", description: "Token mint address" } }, required: ["walletName", "tokenMint"] }
- src/index.ts:128-145 (registration)Tool object registration in the tools array used by ListToolsRequestSchema handler, including name, description, and input schema.{ name: "get_token_balance", description: "Get SPL token balance for a wallet", inputSchema: { type: "object", properties: { walletName: { type: "string", description: "Name of the wallet" }, tokenMint: { type: "string", description: "Token mint address" } }, required: ["walletName", "tokenMint"] } },
- src/index.ts:1297-1299 (registration)Dispatch registration in the CallToolRequestSchema switch statement that routes calls to the handleGetTokenBalance handler.case "get_token_balance": result = await handleGetTokenBalance(args); break;