get-account-balance
Check SOL and token balances for any Solana account on the Pump.fun platform. Verify account holdings and monitor token positions with optional specific token address lookup.
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)Main handler function that loads the account keypair, fetches SOL balance, and optionally fetches token balance using helpers.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 MCP tool 'get-account-balance' with Zod input schema and async handler that calls the implementation 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" }`, }, ], }; } } );
- src/utils.ts:60-86 (helper)Helper utility to retrieve the SPL token balance for a given mint and owner public key, used when tokenAddress is provided.async function getSPLBalance( connection: Connection, mint: PublicKey, owner: PublicKey ): Promise<number | null> { try { const tokenAccounts = await connection.getParsedTokenAccountsByOwner( owner, { mint, } ); if (tokenAccounts.value.length === 0) { return null; } const tokenAccount = tokenAccounts.value[0]; const parsedInfo = tokenAccount.account.data.parsed.info; const balance = parsedInfo.tokenAmount.uiAmount; return balance; } catch (error) { console.error("Error getting SPL balance:", error); return null; } }