getWalletBalance
Query the Ethereum balance of a specific wallet address on any supported network using the provided address and optional network details like provider or chain ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | The Ethereum address to query | |
| chainId | No | Optional. The chain ID to use. If provided with a named network and they don't match, the RPC's chain ID will be used. | |
| provider | No | Optional. Either a network name or custom RPC URL. Use getAllNetworks to see available networks and their details, or getNetwork to get info about a specific network. You can use any network name returned by these tools as a provider value. |
Implementation Reference
- src/tools/core.ts:244-276 (registration)Registration of the getWalletBalance tool using server.tool(). Includes inline input schema (using shared addressSchema) and the complete async handler function that fetches the balance from the provider.// Get wallet balance server.tool( "getWalletBalance", { address: addressSchema.describe( "The Ethereum address to query" ), provider: z.string().optional().describe(PROVIDER_DESCRIPTION), chainId: z.number().optional().describe( "Optional. The chain ID to use. If provided with a named network and they don't match, the RPC's chain ID will be used." ) }, async ({ address, provider, chainId }) => { try { // Get the balance in wei directly from the provider const selectedProvider = provider ? ethersService.getProvider(provider, chainId) : ethersService.provider; const balanceWei = await selectedProvider.getBalance(address); const balanceEth = ethers.formatEther(balanceWei); return { content: [{ type: "text", text: `Balance of ${address}: ${balanceEth} ETH (${balanceWei.toString()} wei)` }] }; } catch (error) { return createErrorResponse(error, 'getting wallet balance'); } } );
- src/utils/validation.ts:257-260 (schema)Shared Zod schema for Ethereum addresses (CommonSchemas.ethereumAddress), referenced in the getWalletBalance tool schema.ethereumAddress: z.string().regex( /^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address. Expected format: 0x followed by 40 hexadecimal characters (e.g., 0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7)' ),
- src/tools/index.ts:23-23 (registration)High-level registration call for core tools (including getWalletBalance) within the registerAllTools function.registerCoreTools(server, ethersService);