Skip to main content
Glama

get_token_balance

Retrieve SPL token balances for specific wallets on the Solana blockchain by providing wallet names and token mint addresses.

Instructions

Get SPL token balance for a wallet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
walletNameYesName of the wallet
tokenMintYesToken mint address

Implementation Reference

  • The handler function that implements the get_token_balance tool logic: retrieves the wallet, computes the associated token account for the given mint, fetches the account info, and returns the balance or handles errors.
    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" }; } }
  • Input schema defining the parameters for the get_token_balance tool: walletName (string) and tokenMint (string), both required.
    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)
    Tool object registration in the tools array used by ListToolsRequestSchema handler, 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-1299 (registration)
    Dispatch registration in the CallToolRequestSchema switch statement that routes calls to the handleGetTokenBalance handler.
    case "get_token_balance": result = await handleGetTokenBalance(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