Skip to main content
Glama

get-balance

Check your current SOL wallet balance to monitor funds and manage payments within the X402 payment system.

Instructions

Check the current SOL balance in your wallet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function that creates a Solana connection on devnet, derives the public key from the environment private key, fetches the balance in lamports, converts to SOL, and returns formatted text response or error.
    async () => { try { const signer = await createSigner("solana-devnet", process.env.SOLANA_PRIVATE_KEY || " "); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const privateKeyBytes = bs58.decode(process.env.SOLANA_PRIVATE_KEY || ""); const keypair = Keypair.fromSecretKey(privateKeyBytes); const publicKey = keypair.publicKey; const balance = await connection.getBalance(publicKey); const solBalance = balance / LAMPORTS_PER_SOL; return { content: [{ type: "text", text: JSON.stringify({ balance: solBalance, unit: "SOL", network: "devnet", address: publicKey }, null, 2) }] }; } catch (err: any) { return { content: [{ type: "text", text: `Error: ${err.message || "Failed to get balance"}` }], isError: true }; } }
  • Tool schema with title, description, and empty input schema (no parameters required).
    { title: "Get Wallet Balance", description: "Check the current SOL balance in your wallet", inputSchema: {}, },
  • src/index.ts:30-72 (registration)
    Registers the 'get-balance' tool on the MCP server with schema and inline handler function.
    server.registerTool( "get-balance", { title: "Get Wallet Balance", description: "Check the current SOL balance in your wallet", inputSchema: {}, }, async () => { try { const signer = await createSigner("solana-devnet", process.env.SOLANA_PRIVATE_KEY || " "); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const privateKeyBytes = bs58.decode(process.env.SOLANA_PRIVATE_KEY || ""); const keypair = Keypair.fromSecretKey(privateKeyBytes); const publicKey = keypair.publicKey; const balance = await connection.getBalance(publicKey); const solBalance = balance / LAMPORTS_PER_SOL; return { content: [{ type: "text", text: JSON.stringify({ balance: solBalance, unit: "SOL", network: "devnet", address: publicKey }, null, 2) }] }; } catch (err: any) { return { content: [{ type: "text", text: `Error: ${err.message || "Failed to get balance"}` }], isError: true }; } } );

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/Kishore-MK/ai42-mcp'

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