getEthBalance
Retrieve the current Ether balance for any Ethereum wallet address to monitor holdings or verify transactions on the blockchain.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes |
Implementation Reference
- tools/balance.js:13-25 (handler)The handler function that retrieves the ETH balance for the given address using Web3, converts from wei to ETH, and returns a formatted text response or error.async ({ address }) => { try { const balanceWei = await web3.eth.getBalance(address); const balanceEth = web3.utils.fromWei(balanceWei, 'ether'); return { content: [{ type: "text", text: `Balance for ${address}: ${balanceEth} ETH` }] }; } catch (error) { return { content: [{ type: "text", text: `Error fetching balance: ${error.message}` }] }; } }
- tools/balance.js:12-12 (schema)Zod schema validating the input address as a valid Ethereum address (0x followed by 40 hex chars).{ address: z.string().regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address") },
- tools/balance.js:11-26 (registration)Registers the getEthBalance tool on the MCP server with schema and handler.server.tool("getEthBalance", { address: z.string().regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address") }, async ({ address }) => { try { const balanceWei = await web3.eth.getBalance(address); const balanceEth = web3.utils.fromWei(balanceWei, 'ether'); return { content: [{ type: "text", text: `Balance for ${address}: ${balanceEth} ETH` }] }; } catch (error) { return { content: [{ type: "text", text: `Error fetching balance: ${error.message}` }] }; } } );