Skip to main content
Glama

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
NameRequiredDescriptionDefault
addressYesThe Ethereum address to query
chainIdNoOptional. The chain ID to use. If provided with a named network and they don't match, the RPC's chain ID will be used.
providerNoOptional. 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

  • 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'); } } );
  • 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)' ),
  • High-level registration call for core tools (including getWalletBalance) within the registerAllTools function.
    registerCoreTools(server, ethersService);

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/crazyrabbitLTC/mcp-ethers-server'

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