get_token_balance
Retrieve SPL token balance for a specified wallet and token mint address on the Solana blockchain.
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. It retrieves the SPL token balance from the associated token account for the given wallet and token mint, handling errors if the account does not exist.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)The input schema defining the parameters for the get_token_balance tool: walletName and tokenMint.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)The tool registration in the tools array, used by ListToolsRequestSchema, 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-1298 (registration)The dispatch case in the CallToolRequestSchema handler that routes calls to the get_token_balance handler function.case "get_token_balance": result = await handleGetTokenBalance(args);