Skip to main content
Glama

get_balance

Retrieve the native token balance (ETH, MATIC, etc.) for a wallet address or ENS name across 30+ EVM-compatible networks using the EVM MCP Server.

Instructions

Get the native token balance (ETH, MATIC, etc.) for an address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesThe wallet address or ENS name (e.g., '0x1234...' or 'vitalik.eth') to check the balance for
networkNoNetwork name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. Supports all EVM-compatible networks. Defaults to Ethereum mainnet.

Implementation Reference

  • Registration of the 'get_balance' tool, including input schema, annotations, and the handler function that fetches and formats the balance using services.getETHBalance
    server.registerTool( "get_balance", { description: "Get the native token balance (ETH, MATIC, etc.) for an address", inputSchema: { address: z.string().describe("The wallet address or ENS name"), network: z.string().optional().describe("Network name or chain ID. Defaults to Ethereum mainnet.") }, annotations: { title: "Get Native Token Balance", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true } }, async ({ address, network = "ethereum" }) => { try { const balance = await services.getETHBalance(address as Address, network); return { content: [{ type: "text", text: JSON.stringify({ network, address, balance: { wei: balance.wei.toString(), ether: balance.ether } }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error fetching balance: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
  • Handler function for 'get_balance' tool that calls the service, formats the response as JSON, and handles errors
    async ({ address, network = "ethereum" }) => { try { const balance = await services.getETHBalance(address as Address, network); return { content: [{ type: "text", text: JSON.stringify({ network, address, balance: { wei: balance.wei.toString(), ether: balance.ether } }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error fetching balance: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
  • Input schema for 'get_balance' tool using Zod validation for address and optional network
    address: z.string().describe("The wallet address or ENS name"), network: z.string().optional().describe("Network name or chain ID. Defaults to Ethereum mainnet.") },
  • Core helper function getETHBalance that resolves ENS if needed, fetches balance using viem client.getBalance, and formats it to wei and ether units
    export async function getETHBalance( addressOrEns: string, network = 'ethereum' ): Promise<{ wei: bigint; ether: string }> { // Resolve ENS name to address if needed const address = await resolveAddress(addressOrEns, network); const client = getPublicClient(network); const balance = await client.getBalance({ address }); return { wei: balance, ether: formatEther(balance) }; }

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/mcpdotdirect/evm-mcp-server'

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