Skip to main content
Glama

getEthBalance

Retrieve the current Ether balance for any Ethereum wallet address to monitor holdings or verify transactions on the blockchain.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes

Implementation Reference

  • 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}` }] }; } }
  • 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}` }] }; } } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/0xGval/evm-mcp-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server