Skip to main content
Glama

get-balance

Check your current SOL wallet balance to monitor funds and manage payments within the AI42-MCP X402 Payment Server.

Instructions

Check the current SOL balance in your wallet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'get-balance' tool. It creates a signer, connects to Solana devnet RPC, derives the public key from the private key in SOLANA_PRIVATE_KEY env var, fetches the balance, converts lamports to SOL, and returns formatted JSON 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 }; } }
  • Schema definition for the 'get-balance' tool, including 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)
    Full registration of the 'get-balance' tool via server.registerTool, including name, 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