get_balance
Retrieve the current SOL balance for a specified Solana wallet to monitor cryptocurrency holdings.
Instructions
Get SOL balance for a wallet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| walletName | Yes | Name of the wallet |
Implementation Reference
- src/index.ts:114-127 (registration)Registers the 'get_balance' tool in the tools list returned by ListToolsRequestSchema, including its name, description, and input schema requiring 'walletName'.{ name: "get_balance", description: "Get SOL balance for a wallet", inputSchema: { type: "object", properties: { walletName: { type: "string", description: "Name of the wallet" } }, required: ["walletName"] } },
- src/index.ts:583-603 (handler)The main handler function for 'get_balance' tool. Retrieves the wallet by name, ensures Solana connection, fetches balance using connection.getBalance, converts to SOL, and returns formatted balance info.async function handleGetBalance(args: any) { const { walletName } = args; const wallet = wallets.get(walletName); if (!wallet) { throw new Error(`Wallet '${walletName}' not found`); } ensureConnection(); const balance = await withTimeout(connection.getBalance(wallet.keypair.publicKey)); const solBalance = balance / LAMPORTS_PER_SOL; return { wallet: walletName, address: wallet.keypair.publicKey.toString(), balance: { lamports: balance, sol: solBalance } }; }
- src/index.ts:1294-1296 (registration)Dispatches the 'get_balance' tool call to the handleGetBalance function within the CallToolRequestSchema handler.case "get_balance": result = await handleGetBalance(args); break;