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
| Name | Required | Description | Default |
|---|---|---|---|
| accountName | No | Name of the account to check | default |
| tokenAddress | No | Optional token address to check balance for |
Implementation Reference
- src/get-token-balance.ts:15-60 (handler)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" }`, }, ], }; } } );