Skip to main content
Glama
0xKoda
by 0xKoda

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
NameRequiredDescriptionDefault
addressYesThe Ethereum address to check balance
blockParameterNoBlock parameter (default: "latest")latest

Implementation Reference

  • 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
        };
      }
    }
  • 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
          };
        }
      }
    );
  • 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;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('retrieves') but fails to add context such as read-only nature, potential rate limits, authentication needs, or error conditions. This leaves significant gaps in understanding the tool's behavior beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that directly states the tool's purpose without unnecessary words. It is front-loaded and efficiently conveys the core functionality, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the absence of annotations and output schema, the description is incomplete for a tool with two parameters and no behavioral context. It adequately states what the tool does but lacks details on usage, behavioral traits, or return values, which are crucial for effective agent operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, meaning the input schema already fully documents the parameters (address and blockParameter). The description does not add any additional meaning or clarification beyond what the schema provides, so it meets the baseline for adequate but unenhanced parameter semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('retrieves') and resource ('balance of a given Ethereum address'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like eth_gasPrice or eth_getCode, which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives or any contextual prerequisites. It lacks explicit usage scenarios, exclusions, or comparisons to sibling tools, leaving the agent without direction on tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/0xKoda/eth-mcp'

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