wallet_get_balance
Retrieve the balance of an Ethereum or EVM-compatible wallet using a private key, mnemonic, or JSON. Optionally, specify a block tag to query the balance at a specific point in time.
Instructions
Get the balance of the wallet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blockTag | No | Optional block tag (latest, pending, etc.) | |
| wallet | No | The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set. |
Implementation Reference
- src/handlers/wallet.ts:220-234 (handler)The main handler function for wallet_get_balance tool. It gets the wallet instance, calls getBalance on it with optional blockTag, formats the result, and returns a success or error response.export const getBalanceHandler = async (input: any): Promise<ToolResultSchema> => { try { const wallet = await getWallet(input.wallet, input.password); const balance = await wallet.getBalance(input.blockTag ?? "latest"); return createSuccessResponse( `Wallet balance retrieved successfully Balance: ${balance.toString()} Balance in ETH: ${ethers.utils.formatEther(balance)} `); } catch (error) { return createErrorResponse(`Failed to get wallet balance: ${(error as Error).message}`); } };
- src/tools.ts:176-187 (schema)The input schema definition for the wallet_get_balance tool, including name, description, and inputSchema properties.{ name: "wallet_get_balance", description: "Get the balance of the wallet", inputSchema: { type: "object", properties: { wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." }, blockTag: { type: "string", description: "Optional block tag (latest, pending, etc.)" } }, required: [] } },
- src/tools.ts:572-572 (registration)The registration entry in the handlers dictionary that maps 'wallet_get_balance' to the getBalanceHandler function."wallet_get_balance": getBalanceHandler,