Skip to main content
Glama

get-account-balance

Retrieve SOL and token balances for a specific account on the Pump.fun platform. Specify the account name and optional token address to check balances efficiently.

Instructions

Get the SOL and token balances for an account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountNameNoName of the account to checkdefault
tokenAddressNoOptional token address to check balance for

Implementation Reference

  • Core handler function that loads the account keypair from the .keys folder, fetches SOL balance, and optionally token balance using getSPLBalance.
    export async function getAccountBalance( accountName: string = "default", tokenAddress?: string ): Promise<string> { try { const { connection } = initializeSDK(); const keysFolder = path.resolve(rootDir, ".keys"); const accountFilePath = path.join(keysFolder, `${accountName}.json`); if (!fs.existsSync(accountFilePath)) { throw new Error(`Account file not found for ${accountName}`); } const keypairData = JSON.parse(fs.readFileSync(accountFilePath, "utf-8")); const keypair = Keypair.fromSecretKey(new Uint8Array(keypairData)); const solBalance = await connection.getBalance(keypair.publicKey); let response = [ `Account: ${accountName} (${keypair.publicKey.toString()})`, `SOL Balance: ${solBalance / LAMPORTS_PER_SOL} SOL`, ]; if (tokenAddress) { const mintPublicKey = new PublicKey(tokenAddress); const tokenBalance = await getSPLBalance( connection, mintPublicKey, keypair.publicKey ); response.push( `Token Balance (${tokenAddress}): ${ tokenBalance !== null ? tokenBalance : "No token account found" }` ); } return response.join("\n"); } catch (error: any) { console.error("Error getting account balance:", error); return `Error getting account balance: ${ error?.message || "Unknown error" }`; } }
  • src/index.ts:275-313 (registration)
    Registers the get-account-balance tool with the MCP server, including input schema and a thin wrapper that calls the handler function.
    server.tool( "get-account-balance", "Get the SOL and token balances for an account", { accountName: z .string() .default("default") .describe("Name of the account to check"), tokenAddress: z .string() .optional() .describe("Optional token address to check balance for"), }, async ({ accountName, tokenAddress }) => { try { const result = await getAccountBalance(accountName, tokenAddress); return { content: [ { type: "text", text: result, }, ], }; } catch (error: any) { console.error("Error getting account balance:", error); return { content: [ { type: "text", text: `Error getting account balance: ${ error?.message || "Unknown error" }`, }, ], }; } } );

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/noahgsolomon/pumpfun-mcp-server'

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