get_balance
Retrieve native token balances (like ETH or MATIC) for any wallet address across EVM-compatible blockchain networks to monitor account holdings.
Instructions
Get the native token balance (ETH, MATIC, etc.) for an address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | The wallet address or ENS name | |
| network | No | Network name or chain ID. Defaults to Ethereum mainnet. |
Implementation Reference
- src/core/tools.ts:263-312 (registration)Primary registration of the 'get_balance' MCP tool. Includes inline Zod schema for input validation (address and optional network), description, and handler function that resolves the address via ENS if needed, fetches balance using services.getETHBalance, formats wei/ether, and returns structured JSON response or error.'get_balance', 'Get the native token balance (ETH, MATIC, etc.) for an address', { address: z .string() .describe( "The wallet address or ENS name (e.g., '0x1234...' or 'vitalik.eth') to check the balance for" ), network: z .string() .optional() .describe( "Network name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. Supports all EVM-compatible networks. Defaults to Ethereum mainnet." ) }, async ({ address, network = 'ethereum' }) => { try { const balance = await services.getETHBalance(address, network); return { content: [ { type: 'text', text: JSON.stringify( { address, network, 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 }; } } );
- src/core/services/balance.ts:75-89 (handler)Core handler logic for fetching native token (ETH) balance. Resolves ENS names to addresses, uses viem's public client to call getBalance, and formats the result into wei bigint and human-readable ether string.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) }; }
- src/server/server.ts:17-19 (registration)Server initialization where registerEVMTools(server) is called, which registers the get_balance tool among other EVM tools.registerEVMResources(server); registerEVMTools(server); registerEVMPrompts(server);
- src/core/services/index.ts:2-2 (helper)Re-export of balance service functions (including getETHBalance) as 'services' namespace used by the tool handler.export * from './clients.js';