Skip to main content
Glama

get_balance

Retrieve the SOL balance for a specified Solana wallet to monitor cryptocurrency holdings.

Instructions

Get SOL balance for a wallet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
walletNameYesName of the wallet

Implementation Reference

  • The handler function that executes the get_balance tool logic. It retrieves the wallet by name, ensures connection, fetches the balance using Solana's connection.getBalance with timeout, 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 } }; }
  • The input schema definition for the get_balance tool, specifying the required 'walletName' parameter.
    inputSchema: { type: "object", properties: { walletName: { type: "string", description: "Name of the wallet" } }, required: ["walletName"] }
  • src/index.ts:114-127 (registration)
    The tool registration entry in the tools array, including name, description, and input schema. This is returned by ListToolsRequestSchema.
    { 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:1294-1296 (registration)
    The dispatch case in the CallToolRequestSchema handler that routes 'get_balance' calls to the handleGetBalance function.
    case "get_balance": result = await handleGetBalance(args); break;
  • Helper function withTimeout used by get_balance handler to wrap connection.getBalance with a 10-second timeout.
    async function withTimeout<T>(promise: Promise<T>, timeoutMs: number = 10000): Promise<T> { const timeoutPromise = new Promise<never>((_, reject) => { setTimeout(() => reject(new Error('Operation timed out')), timeoutMs); }); return Promise.race([promise, timeoutPromise]); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ExpertVagabond/solana-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server