Skip to main content
Glama

eth_getBalance

Check the balance of any Ethereum or EVM-compatible blockchain account by providing the wallet address and optional block number to query current or historical token holdings.

Instructions

Returns the balance of the account of given address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesAddress to check balance for
blockNumberNoBlock number or 'latest', 'earliest', 'pending'latest

Implementation Reference

  • Full server.tool registration which defines and registers the handler function for eth_getBalance. The handler performs an RPC call to eth_getBalance, formats the balance from wei to ETH, handles errors, and returns a formatted text response.
    server.tool(
      "eth_getBalance",
      "Returns the balance of the account of given address",
      {
        address: z.string().describe("Address to check balance for"),
        blockNumber: z
          .string()
          .optional()
          .default("latest")
          .describe("Block number or 'latest', 'earliest', 'pending'"),
      },
      async ({ address, blockNumber }) => {
        try {
          const result = await makeRPCCall("eth_getBalance", [
            address,
            blockNumber,
          ]);
          const balance = ethers.formatEther(result);
          return {
            content: [
              {
                type: "text",
                text: formatResponse(
                  {
                    address,
                    balance_wei: result,
                    balance_eth: balance,
                    block: blockNumber,
                  },
                  "Account Balance",
                ),
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: "text",
                text: `Error: ${error.message}`,
              },
            ],
          };
        }
      },
    );
  • Input schema using Zod for validating address (required string) and blockNumber (optional string, defaults to 'latest').
    {
      address: z.string().describe("Address to check balance for"),
      blockNumber: z
        .string()
        .optional()
        .default("latest")
        .describe("Block number or 'latest', 'earliest', 'pending'"),
    },
  • Generic helper function used by the handler to send the 'eth_getBalance' RPC method to the Ethers JsonRpcProvider.
    async function makeRPCCall(method: string, params: any[] = []): Promise<any> {
      try {
        const result = await provider.send(method, params);
        return result;
      } catch (error: any) {
        throw new Error(`RPC call failed: ${error.message}`);
      }
    }
  • Helper function used to format the tool's response as structured markdown text.
    function formatResponse(data: any, title: string): string {
      let result = `**${title}**\n\n`;
    
      if (typeof data === "object" && data !== null) {
        if (Array.isArray(data)) {
          // Handle arrays
          result += `**Count:** ${data.length}\n\n`;
          data.forEach((item, index) => {
            result += `**${index + 1}.**\n`;
            if (typeof item === "object" && item !== null) {
              result += formatObject(item, "  ");
            } else {
              result += `  ${item}\n`;
            }
            result += "\n";
          });
        } else {
          // Handle objects
          result += formatObject(data, "");
        }
      } else {
        result += `${data}\n`;
      }
    
      return result;
    }
  • src/index.ts:194-239 (registration)
    Explicit registration of the tool with the MCP server instance.
    server.tool(
      "eth_getBalance",
      "Returns the balance of the account of given address",
      {
        address: z.string().describe("Address to check balance for"),
        blockNumber: z
          .string()
          .optional()
          .default("latest")
          .describe("Block number or 'latest', 'earliest', 'pending'"),
      },
      async ({ address, blockNumber }) => {
        try {
          const result = await makeRPCCall("eth_getBalance", [
            address,
            blockNumber,
          ]);
          const balance = ethers.formatEther(result);
          return {
            content: [
              {
                type: "text",
                text: formatResponse(
                  {
                    address,
                    balance_wei: result,
                    balance_eth: balance,
                    block: blockNumber,
                  },
                  "Account Balance",
                ),
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: "text",
                text: `Error: ${error.message}`,
              },
            ],
          };
        }
      },
    );
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 it 'Returns the balance' but doesn't specify units (e.g., wei, ether), error conditions, rate limits, or authentication needs. For a read operation with zero annotation coverage, this is a significant gap in transparency.

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, efficient sentence with zero waste. It's front-loaded with the core purpose, making it highly concise and well-structured for quick understanding.

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 complexity of blockchain queries, no annotations, and no output schema, the description is incomplete. It lacks details on return format (e.g., numeric balance in wei), error handling, or dependencies. For a tool with 2 parameters and rich context signals, this minimal description is inadequate.

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%, so the schema already documents both parameters (address and blockNumber) adequately. The description implies the address parameter but doesn't add syntax, format, or contextual details beyond what the schema provides. Baseline 3 is appropriate when the schema handles parameter documentation.

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 ('Returns') and resource ('balance of the account'), making the purpose specific and understandable. It distinguishes from siblings like eth_getTransactionCount or eth_getCode by focusing on balance retrieval. However, it doesn't explicitly contrast with all siblings, preventing 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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites, context, or comparisons to other tools (e.g., eth_call for more complex queries). This leaves the agent without explicit usage instructions.

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/JamesANZ/evm-mcp'

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