eth_getBalance
Retrieve the current or historical Ether balance of any Ethereum wallet address to verify holdings or track transactions.
Instructions
Retrieves the balance of a given Ethereum address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | The Ethereum address to check balance | |
| blockParameter | No | Block parameter (default: "latest") | latest |
Implementation Reference
- index.js:172-193 (handler)The handler function that performs the eth_getBalance RPC call via makeRpcCall, converts the balance from wei to ETH, and returns a formatted text response.async (args) => { try { console.error(`Getting balance for address: ${args.address} at block: ${args.blockParameter}`); const balance = await makeRpcCall('eth_getBalance', [args.address, args.blockParameter]); // Convert hex balance to decimal and then to ETH for readability const balanceWei = parseInt(balance, 16); const balanceEth = balanceWei / 1e18; return { content: [{ type: "text", text: `Balance for ${args.address}:\n${balanceWei} Wei\n${balanceEth.toFixed(6)} ETH` }] }; } catch (error) { return { content: [{ type: "text", text: `Error: Failed to get balance. ${error.message}` }], isError: true }; } }
- index.js:168-171 (schema)Zod input schema defining the parameters for the eth_getBalance tool: address (required, Ethereum address format) and blockParameter (optional, defaults to 'latest').{ address: z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe('The Ethereum address to check balance'), blockParameter: z.string().default('latest').describe('Block parameter (default: "latest")') },
- index.js:165-194 (registration)MCP server.tool registration for the eth_getBalance tool, including name, description, input schema, and handler function.server.tool( 'eth_getBalance', 'Retrieves the balance of a given Ethereum address', { address: z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe('The Ethereum address to check balance'), blockParameter: z.string().default('latest').describe('Block parameter (default: "latest")') }, async (args) => { try { console.error(`Getting balance for address: ${args.address} at block: ${args.blockParameter}`); const balance = await makeRpcCall('eth_getBalance', [args.address, args.blockParameter]); // Convert hex balance to decimal and then to ETH for readability const balanceWei = parseInt(balance, 16); const balanceEth = balanceWei / 1e18; return { content: [{ type: "text", text: `Balance for ${args.address}:\n${balanceWei} Wei\n${balanceEth.toFixed(6)} ETH` }] }; } catch (error) { return { content: [{ type: "text", text: `Error: Failed to get balance. ${error.message}` }], isError: true }; } } );
- index.js:84-102 (helper)Helper function used by eth_getBalance (and other tools) to make POST requests to the Ethereum RPC endpoint and handle responses/errors.async function makeRpcCall(method, params = []) { try { const response = await axios.post(ETH_RPC_URL, { jsonrpc: '2.0', id: 1, method, params }); if (response.data.error) { throw new Error(`RPC Error: ${response.data.error.message}`); } return response.data.result; } catch (error) { console.error(`Error making RPC call to ${method}:`, error.message); throw error; } }