get_balance
Check USDC and SOL balances in the agent wallet on Solana devnet to monitor cryptocurrency holdings.
Instructions
Check the USDC and SOL balance of the agent wallet. Returns balances on Solana devnet.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:34-42 (registration)Registration of the 'get_balance' tool in the TOOLS array, including name, description, and empty input schema.{ name: "get_balance", description: "Check the USDC and SOL balance of the agent wallet. Returns balances on Solana devnet.", inputSchema: { type: "object", properties: {}, required: [], }, },
- src/index.ts:135-145 (handler)MCP server handler for 'get_balance' tool call: invokes wallet.getBalances() and returns JSON-formatted response.case "get_balance": { const balances = await wallet.getBalances(); return { content: [ { type: "text", text: JSON.stringify(balances, null, 2), }, ], }; }
- src/wallet.ts:109-133 (helper)Core implementation of getBalances() in AgentWallet class: fetches SOL balance via connection.getBalance and USDC balance via SPL token account.async getBalances(): Promise<BalanceInfo> { const address = this.keypair.publicKey; // Get SOL balance const solBalance = await this.connection.getBalance(address); const sol = solBalance / LAMPORTS_PER_SOL; // Get USDC balance let usdc = 0; try { const usdcAta = await getAssociatedTokenAddress(USDC_MINT, address); const tokenAccount = await getAccount(this.connection, usdcAta); usdc = Number(tokenAccount.amount) / Math.pow(10, USDC_DECIMALS); } catch { // Token account doesn't exist yet usdc = 0; } return { sol: parseFloat(sol.toFixed(4)), usdc: parseFloat(usdc.toFixed(2)), network: "devnet", address: address.toBase58(), }; }
- src/wallet.ts:36-40 (schema)TypeScript interface defining the output structure for balance information.sol: number; usdc: number; network: string; address: string; }