Skip to main content
Glama

getERC20TokenInfo

Retrieve ERC20 token details including name, symbol, decimals, and total supply by providing the token contract address.

Instructions

Get detailed information about an ERC20 token including its name, symbol, decimals, and total supply. Requires the contract address of the token.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractAddressYesThe address of the ERC20 token contract
tokenAddressNoDEPRECATED: Use contractAddress instead. The address of the ERC20 token contract
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

  • Primary MCP tool handler for getERC20TokenInfo. Maps parameters, calls ethersService, formats and returns token information or error.
        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 tokenInfo = await ethersService.getERC20TokenInfo(
              contractAddr,
              mapped.provider,
              mapped.chainId
            );
            
            return {
              content: [{ 
                type: "text", 
                text: `Token Information:
    Name: ${tokenInfo.name}
    Symbol: ${tokenInfo.symbol}
    Decimals: ${tokenInfo.decimals}
    Total Supply: ${tokenInfo.totalSupply}`
              }]
            };
          } catch (error) {
            return {
              isError: true,
              content: [{ 
                type: "text", 
                text: `Error getting token information: ${error instanceof Error ? error.message : String(error)}`
              }]
            };
          }
        }
  • Tool schema definition including name, description, and inputSchema for MCP tool registry.
    {
      name: "getERC20TokenInfo",
      description: "Get basic information about an ERC20 token including name, symbol, decimals, and total supply",
      inputSchema: {
        type: "object",
        properties: {
          tokenAddress: {
            type: "string",
            description: "The address of the ERC20 token contract"
          },
          provider: {
            type: "string",
            description: "Optional. Either a network name or custom RPC URL. Use getSupportedNetworks to get a list of supported networks."
          },
          chainId: {
            type: "number",
            description: "Optional. The chain ID to use. If provided with a named network and they don't match, the RPC's chain ID will be used."
          }
        },
        required: ["tokenAddress"]
      }
    },
  • MCP server.tool registration for getERC20TokenInfo with zod input schema, description, and inline handler function.
        "getERC20TokenInfo",
        "Get detailed information about an ERC20 token including its name, symbol, decimals, and total supply. Requires the contract address of the token.",
        {
          contractAddress: contractAddressSchema,
          tokenAddress: tokenAddressSchema.optional(),  // Deprecated
          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 tokenInfo = await ethersService.getERC20TokenInfo(
              contractAddr,
              mapped.provider,
              mapped.chainId
            );
            
            return {
              content: [{ 
                type: "text", 
                text: `Token Information:
    Name: ${tokenInfo.name}
    Symbol: ${tokenInfo.symbol}
    Decimals: ${tokenInfo.decimals}
    Total Supply: ${tokenInfo.totalSupply}`
              }]
            };
          } catch (error) {
            return {
              isError: true,
              content: [{ 
                type: "text", 
                text: `Error getting token information: ${error instanceof Error ? error.message : String(error)}`
              }]
            };
          }
        }
      );
  • Core ERC20 helper function that implements token info retrieval using ethers.js Contract interface, with caching, error handling, and metrics.
    export async function getTokenInfo(
      ethersService: EthersService,
      tokenAddress: string,
      provider?: string,
      chainId?: number
    ): Promise<ERC20Info> {
      metrics.incrementCounter('erc20.getTokenInfo');
      
      return timeAsync('erc20.getTokenInfo', async () => {
        try {
          // Check rate limiting
          const identity = `${tokenAddress}:${provider || 'default'}`;
          if (!rateLimiter.consume('token', identity)) {
            throw new ERC20Error('Rate limit exceeded for token operations');
          }
          
          // Create cache key
          const cacheKey = createTokenCacheKey(
            CACHE_KEYS.ERC20_INFO,
            tokenAddress,
            chainId
          );
          
          // Check cache first
          const cachedInfo = contractCache.get(cacheKey);
          if (cachedInfo) {
            return cachedInfo as ERC20Info;
          }
          
          // Get provider from ethers service
          const ethersProvider = ethersService['getProvider'](provider, chainId);
          
          // Create contract instance
          const contract = new ethers.Contract(tokenAddress, ERC20_ABI, ethersProvider);
          
          // Fetch token information
          const [name, symbol, decimals, totalSupply] = await Promise.all([
            contract.name(),
            contract.symbol(),
            contract.decimals(),
            contract.totalSupply()
          ]);
          
          // Format data
          const tokenInfo: ERC20Info = {
            name,
            symbol,
            decimals,
            totalSupply: totalSupply.toString()
          };
          
          // Cache result for future use (1 day TTL)
          contractCache.set(cacheKey, tokenInfo, { ttl: 86400000 });
          
          return tokenInfo;
        } catch (error) {
          logger.debug('Error getting ERC20 token info', { tokenAddress, error });
          
          if (error instanceof Error && (
            error.message.includes('contract not deployed') || 
            error.message.includes('invalid address')
          )) {
            throw new TokenNotFoundError(tokenAddress);
          }
          
          throw handleTokenError(error, 'Failed to get token information');
        }
      });
    }
  • Top-level registration call within registerAllTools that invokes ERC20 tool registrations including getERC20TokenInfo.
    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 retrieves information (implying a read-only operation) but doesn't mention potential errors (e.g., invalid addresses), rate limits, authentication needs, or network dependencies. For a tool with no annotations, this leaves significant behavioral gaps.

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 concise and front-loaded, with two sentences that directly state the purpose and a key requirement. There's no wasted text, though it could be slightly more structured (e.g., separating usage notes).

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 (4 parameters, no annotations, no output schema), the description is incomplete. It lacks details on return values, error handling, network behavior, and differentiation from siblings. Without annotations or output schema, more context is needed for effective tool use.

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%, so the schema already documents all parameters thoroughly. The description adds minimal value by implying the 'contractAddress' is required, but doesn't provide additional context beyond what's in the schema. This meets the baseline for high schema coverage.

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 detailed information about an ERC20 token including its name, symbol, decimals, and total supply.' It specifies the verb ('Get') and resource ('ERC20 token') with concrete data fields. However, it doesn't distinguish from sibling tools like 'erc20_getTokenInfo' or 'getERC20Balance', which is a minor gap.

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 minimal usage guidance: it mentions 'Requires the contract address of the token,' which is a prerequisite but not a contextual guideline. There's no explicit advice on when to use this tool versus alternatives like 'erc20_getTokenInfo' or 'getERC20Balance', nor any exclusions or best practices.

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