Skip to main content
Glama

getBalance

Check the SOL balance of a specific Solana account address using a simple RPC endpoint provided by the Solana MCP Server.

Instructions

Get balance for a Solana address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesSolana account address

Implementation Reference

  • The main execution logic for the getBalance tool. Parses the address into a PublicKey, retrieves the lamports balance from Solana RPC, converts to SOL, and returns formatted response or error.
    async ({ address }) => { try { const publicKey = new PublicKey(address); const balance = await connection.getBalance(publicKey); const solBalance = balance / LAMPORTS_PER_SOL; // Using LAMPORTS_PER_SOL constant return { content: [ { type: "text", text: `Balance for ${address}:\n${solBalance} SOL`, }, ], }; } catch (err) { const error = err as Error; return { content: [ { type: "text", text: `Failed to retrieve balance for address: ${error.message}`, }, ], }; } }
  • Zod input schema validating the 'address' parameter as a string with description.
    { address: z.string().describe("Solana account address"), },
  • src/index.ts:56-88 (registration)
    Calls server.tool() to register the getBalance tool with its name, description, schema, and handler function.
    server.tool( "getBalance", "Get balance for a Solana address", { address: z.string().describe("Solana account address"), }, async ({ address }) => { try { const publicKey = new PublicKey(address); const balance = await connection.getBalance(publicKey); const solBalance = balance / LAMPORTS_PER_SOL; // Using LAMPORTS_PER_SOL constant return { content: [ { type: "text", text: `Balance for ${address}:\n${solBalance} SOL`, }, ], }; } catch (err) { const error = err as Error; return { content: [ { type: "text", text: `Failed to retrieve balance for address: ${error.message}`, }, ], }; } } );

Other Tools

Related Tools

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/akc2267/solana-mcp-server'

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