Skip to main content
Glama

erc20_balanceOf

Check ERC20 token balances for any Ethereum address by specifying the token contract and wallet address.

Instructions

Get the ERC20 token balance for a specific address. Alternative naming for compatibility with MCP client tests.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractAddressYesThe address of the ERC20 token contract
tokenAddressNoDEPRECATED: Use contractAddress instead. The address of the ERC20 token contract
ownerAddressYesThe Ethereum address whose balance to check
providerNoOptional. Either a network name or custom RPC URL. Use getAllNetworks to see available networks and their details, or getNetwork to get info about a specific network. You can use any network name returned by these tools as a provider value.
chainIdNoOptional. The chain ID to use. If provided with a named network and they don't match, the RPC's chain ID will be used.

Implementation Reference

  • The handler function executing the erc20_balanceOf tool logic. Maps input parameters, retrieves the ERC20 token balance and symbol using EthersService, formats a user-friendly response.
    async (params) => {
      // Map deprecated parameters
      const mapped = mapParameters(params);
      
      try {
        const contractAddr = mapped.contractAddress || params.tokenAddress;
        if (!contractAddr) {
          throw new Error('Either contractAddress or tokenAddress must be provided');
        }
        const balance = await ethersService.getERC20Balance(
          mapped.ownerAddress,
          contractAddr,
          mapped.provider,
          mapped.chainId
        );
        
        // Get token info to format the response
        const tokenInfo = await ethersService.getERC20TokenInfo(
          contractAddr,
          mapped.provider,
          mapped.chainId
        );
        
        return {
          content: [{ 
            type: "text", 
            text: `${mapped.ownerAddress} has a balance of ${balance} ${tokenInfo.symbol}`
          }]
        };
      } catch (error) {
        return {
          isError: true,
          content: [{ 
            type: "text", 
            text: `Error getting token balance: ${error instanceof Error ? error.message : String(error)}`
          }]
        };
      }
    }
  • Input schema validation for the erc20_balanceOf tool using Zod, defining parameters like contractAddress, ownerAddress, provider, and chainId.
    {
      contractAddress: contractAddressSchema,
      tokenAddress: tokenAddressSchema.optional(),  // Deprecated
      ownerAddress: z.string().describe(
        "The Ethereum address whose balance to check"
      ),
      provider: providerSchema,
      chainId: chainIdSchema
    },
  • Direct MCP server.tool registration for the erc20_balanceOf tool, including description, schema, and inline handler.
    "erc20_balanceOf",
    "Get the ERC20 token balance for a specific address. Alternative naming for compatibility with MCP client tests.",
    {
      contractAddress: contractAddressSchema,
      tokenAddress: tokenAddressSchema.optional(),  // Deprecated
      ownerAddress: z.string().describe(
        "The Ethereum address whose balance to check"
      ),
      provider: providerSchema,
      chainId: chainIdSchema
    },
    async (params) => {
      // Map deprecated parameters
      const mapped = mapParameters(params);
      
      try {
        const contractAddr = mapped.contractAddress || params.tokenAddress;
        if (!contractAddr) {
          throw new Error('Either contractAddress or tokenAddress must be provided');
        }
        const balance = await ethersService.getERC20Balance(
          mapped.ownerAddress,
          contractAddr,
          mapped.provider,
          mapped.chainId
        );
        
        // Get token info to format the response
        const tokenInfo = await ethersService.getERC20TokenInfo(
          contractAddr,
          mapped.provider,
          mapped.chainId
        );
        
        return {
          content: [{ 
            type: "text", 
            text: `${mapped.ownerAddress} has a balance of ${balance} ${tokenInfo.symbol}`
          }]
        };
      } catch (error) {
        return {
          isError: true,
          content: [{ 
            type: "text", 
            text: `Error getting token balance: ${error instanceof Error ? error.message : String(error)}`
          }]
        };
      }
    }
  • Top-level registration call to registerERC20Tools, which registers the erc20_balanceOf tool among others.
    registerERC20Tools(server, ethersService);
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'Get[s] the ERC20 token balance,' implying a read-only operation, but doesn't mention any behavioral traits like authentication needs, rate limits, error conditions, or what the return format looks like (e.g., numeric balance, units). For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded, with the core purpose stated clearly in the first sentence. The second sentence about 'Alternative naming for compatibility' adds context but could be considered slightly extraneous. Overall, it's efficient with minimal waste, though not perfectly streamlined.

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 interactions and the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., balance format, units), potential errors, or dependencies like network connectivity. For a tool with 5 parameters and no structured output information, more context is needed to ensure proper usage.

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?

Schema description coverage is 100%, meaning all parameters are documented in the input schema. The description adds no additional meaning beyond the schema—it doesn't explain parameter relationships, usage examples, or constraints. With high schema coverage, the baseline score is 3, as the description doesn't compensate but also doesn't detract from the schema's completeness.

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 tool's purpose: 'Get the ERC20 token balance for a specific address.' It includes a specific verb ('Get') and resource ('ERC20 token balance'), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'getERC20Balance' or 'getWalletBalance', which likely serve similar purposes, 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?

The description provides no guidance on when to use this tool versus alternatives. It mentions 'Alternative naming for compatibility with MCP client tests,' which hints at redundancy but doesn't clarify which sibling tools (e.g., 'getERC20Balance') are preferred or when to choose this one. Without explicit when/when-not instructions or named alternatives, the score is low.

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/crazyrabbitLTC/mcp-ethers-server'

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