Skip to main content
Glama

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
NameRequiredDescriptionDefault
walletNameYesName 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"]
      }
    },
  • 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;

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