compare_balances
Compare native token balances for any address across multiple EVM blockchain networks to analyze cross-chain holdings and distribution patterns.
Instructions
Compare native token balance for an address across multiple EVM chains
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Address to check | |
| blockchains | No | List of blockchain names (optional, defaults to all EVM chains) | |
| network | No | Network type (defaults to mainnet) |
Implementation Reference
- Core tool implementation: Fetches native token (ETH-like) balances for the given address across specified EVM chains using eth_getBalance RPC calls, converts to ETH decimals, aggregates total and counts non-zero balances.async compareBalances( address: string, blockchains?: string[], network: 'mainnet' | 'testnet' = 'mainnet' ): Promise<EndpointResponse> { try { // Get all EVM chains if not specified const chainsToCheck = blockchains || this.getEVMChains(); const results = await Promise.all( chainsToCheck.map(async (blockchain) => { const service = this.blockchainService.getServiceByBlockchain(blockchain, network); if (!service) { return { blockchain, error: 'Service not found', balance: null }; } const result = await this.blockchainService.callRPCMethod( service.id, 'eth_getBalance', [address, 'latest'] ); if (result.success && result.data) { const weiBalance = BigInt(result.data); const ethBalance = Number(weiBalance) / 1e18; return { blockchain, balance: ethBalance, balanceWei: weiBalance.toString(), balanceHex: result.data, }; } return { blockchain, error: result.error, balance: null }; }) ); const totalBalance = results .filter(r => r.balance !== null) .reduce((sum, r) => sum + (r.balance || 0), 0); return { success: true, data: { address, balances: results, totalBalance, chainsWithBalance: results.filter(r => r.balance && r.balance > 0).length, }, metadata: { timestamp: new Date().toISOString(), endpoint: 'multi-chain', }, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Failed to compare balances', }; } }
- MCP tool execution handler: Extracts arguments from tool call, invokes AdvancedBlockchainService.compareBalances, and returns formatted MCP response (JSON text content or error).case 'compare_balances': { const address = args?.address as string; const blockchains = args?.blockchains as string[] | undefined; const network = (args?.network as 'mainnet' | 'testnet') || 'mainnet'; const result = await advancedBlockchain.compareBalances(address, blockchains, network); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; }
- Input JSON Schema: Validates tool parameters - address (required string), blockchains (optional string array), network (optional enum: mainnet/testnet).inputSchema: { type: 'object', properties: { address: { type: 'string', description: 'Address to check', }, blockchains: { type: 'array', items: { type: 'string' }, description: 'List of blockchain names (optional, defaults to all EVM chains)', }, network: { type: 'string', enum: ['mainnet', 'testnet'], description: 'Network type (defaults to mainnet)', }, }, required: ['address'], },
- src/handlers/multichain-handlers.ts:15-38 (registration)Tool registration: Defines the 'compare_balances' tool with name, description, and input schema for MCP server registration via registerMultichainHandlers.{ name: 'compare_balances', description: 'Compare native token balance for an address across multiple EVM chains', inputSchema: { type: 'object', properties: { address: { type: 'string', description: 'Address to check', }, blockchains: { type: 'array', items: { type: 'string' }, description: 'List of blockchain names (optional, defaults to all EVM chains)', }, network: { type: 'string', enum: ['mainnet', 'testnet'], description: 'Network type (defaults to mainnet)', }, }, required: ['address'], }, },