get_balance_ether
Retrieve the Ethereum balance of a specific address using the Arbitrum MCP Server. Input the address and optional RPC URL to access accurate ETH balance details.
Instructions
Get balance of an address in ETH
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Ethereum address to check balance for | |
| rpcUrl | No | The RPC URL of the chain (optional if default is set) |
Implementation Reference
- src/index.ts:252-268 (handler)Handler for the 'get_balance_ether' MCP tool. Resolves RPC URL from chainName or rpcUrl, instantiates EthereumAccountClient, calls getBalanceInEther on the provided address, and returns the balance in ETH as text content.case "get_balance_ether": { const rpcUrl = await this.resolveRpcUrl( (args.rpcUrl as string) || (args.chainName as string) ); const ethereumAccountClient = new EthereumAccountClient(rpcUrl); const balanceEth = await ethereumAccountClient.getBalanceInEther( args.address as string ); return { content: [ { type: "text", text: `Balance: ${balanceEth} ETH`, }, ], }; }
- src/index.ts:962-980 (registration)Tool registration for 'get_balance_ether' including name, description, and input schema defining required 'address' and optional 'rpcUrl' or 'chainName' parameters.{ name: "get_balance_ether", description: "Get balance of an address in ETH", inputSchema: { type: "object" as const, properties: { rpcUrl: { type: "string", description: "The RPC URL of the chain (optional if default is set)", }, address: { type: "string", description: "Ethereum address to check balance for", }, }, required: ["address"], }, },
- Core helper function getBalanceInEther that converts wei balance to ETH format with decimal handling, called by the tool handler. Relies on underlying getBalance method.async getBalanceInEther(address: string): Promise<string> { const weiBalance = await this.getBalance(address); const wei = BigInt(weiBalance); const ether = wei / BigInt('1000000000000000000'); const remainder = wei % BigInt('1000000000000000000'); if (remainder === BigInt(0)) { return ether.toString(); } else { const etherDecimal = Number(wei) / 1e18; return etherDecimal.toFixed(6).replace(/\.?0+$/, ''); } }
- Supporting getBalance method that makes the raw 'eth_getBalance' RPC call to fetch balance in wei.async getBalance(address: string): Promise<string> { const balance = await this.makeRpcCall('eth_getBalance', [address, 'latest']); return balance; }
- Type definitions/interfaces in the client file supporting the Ethereum RPC interactions.export interface Transaction { hash: string; nonce: number; blockHash: string | null; blockNumber: number | null; transactionIndex: number | null; from: string; to: string | null; value: string; gasPrice: string; gas: number; input: string; } export interface Receipt { transactionHash: string; transactionIndex: number; blockHash: string; blockNumber: number; from: string; to: string | null; cumulativeGasUsed: number; gasUsed: number; contractAddress: string | null; logs: any[]; status: string; } export class EthereumAccountClient { private rpcUrl: string; constructor(rpcUrl: string) { this.rpcUrl = rpcUrl; } async getBalance(address: string): Promise<string> { const balance = await this.makeRpcCall('eth_getBalance', [address, 'latest']); return balance; }