Skip to main content
Glama

get_token_balance

Read-onlyIdempotent

Retrieve ERC20 token balances for wallet addresses across EVM networks, supporting ENS names and multiple blockchain networks.

Instructions

Get the ERC20 token balance for an address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesThe wallet address or ENS name
tokenAddressYesThe ERC20 token contract address
networkNoNetwork name or chain ID. Defaults to Ethereum mainnet.

Implementation Reference

  • Registration and handler implementation for the 'get_token_balance' MCP tool. Includes input schema validation with Zod and the execution logic that delegates to services.getERC20Balance.
    'get_token_balance',
    'Get the balance of an ERC20 token for an address',
    {
      tokenAddress: z
        .string()
        .describe(
          "The contract address or ENS name of the ERC20 token (e.g., '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' for USDC or 'uniswap.eth')"
        ),
      ownerAddress: z
        .string()
        .describe(
          "The wallet address or ENS name to check the balance for (e.g., '0x1234...' or 'vitalik.eth')"
        ),
      network: z
        .string()
        .optional()
        .describe(
          "Network name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. Supports all EVM-compatible networks. Defaults to Ethereum mainnet."
        )
    },
    async ({ tokenAddress, ownerAddress, network = 'ethereum' }) => {
      try {
        const balance = await services.getERC20Balance(
          tokenAddress,
          ownerAddress,
          network
        );
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  tokenAddress,
                  owner: ownerAddress,
                  network,
                  raw: balance.raw.toString(),
                  formatted: balance.formatted,
                  symbol: balance.token.symbol,
                  decimals: balance.token.decimals
                },
                null,
                2
              )
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error fetching token balance: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • Core helper function getERC20Balance that implements the actual blockchain query: resolves ENS names, creates viem contract instance, reads balanceOf, symbol, and decimals from the ERC20 token contract.
    export async function getERC20Balance(
      tokenAddressOrEns: string,
      ownerAddressOrEns: string,
      network = 'ethereum'
    ): Promise<{
      raw: bigint;
      formatted: string;
      token: {
        symbol: string;
        decimals: number;
      }
    }> {
      // Resolve ENS names to addresses if needed
      const tokenAddress = await resolveAddress(tokenAddressOrEns, network);
      const ownerAddress = await resolveAddress(ownerAddressOrEns, network);
      
      const publicClient = getPublicClient(network);
    
      const contract = getContract({
        address: tokenAddress,
        abi: erc20Abi,
        client: publicClient,
      });
    
      const [balance, symbol, decimals] = await Promise.all([
        contract.read.balanceOf([ownerAddress]),
        contract.read.symbol(),
        contract.read.decimals()
      ]);
    
      return {
        raw: balance,
        formatted: formatUnits(balance, decimals),
        token: {
          symbol,
          decimals
        }
      };
    }
  • ERC20 ABI definition used by getERC20Balance to read token symbol, decimals, and balanceOf.
    const erc20Abi = [
      {
        inputs: [],
        name: 'symbol',
        outputs: [{ type: 'string' }],
        stateMutability: 'view',
        type: 'function'
      },
      {
        inputs: [],
        name: 'decimals',
        outputs: [{ type: 'uint8' }],
        stateMutability: 'view',
        type: 'function'
      },
      {
        inputs: [{ type: 'address', name: 'account' }],
        name: 'balanceOf',
        outputs: [{ type: 'uint256' }],
        stateMutability: 'view',
        type: 'function'
      }
    ] as const;
  • Top-level registration call that includes get_token_balance via registerEVMTools.
    registerEVMTools(server);
    registerEVMPrompts(server);
Behavior4/5

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

Annotations already provide readOnlyHint=true, destructiveHint=false, openWorldHint=true, and idempotentHint=true, covering safety and idempotency. The description adds no further behavioral context (e.g., rate limits, authentication needs, or return format), but it does not contradict annotations, so it meets the lower bar with annotations present.

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 that directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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

Completeness4/5

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

Given the tool's low complexity, rich annotations (covering safety and idempotency), and full schema coverage, the description is mostly complete. However, the lack of an output schema means the return value (e.g., balance format) is undocumented, leaving a minor gap in completeness.

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%, with clear descriptions for address, tokenAddress, and network parameters. The description adds no additional meaning beyond the schema (e.g., format examples or edge cases), so it meets the baseline of 3 where the schema does the heavy lifting.

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

Purpose5/5

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

The description clearly states the specific action ('Get') and resource ('ERC20 token balance for an address'), distinguishing it from siblings like get_balance (likely for native tokens) or get_erc1155_balance (for different token standards). It precisely identifies the tool's function without ambiguity.

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

Usage Guidelines3/5

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

The description implies usage for ERC20 token balances, but does not explicitly state when to use this tool versus alternatives like get_balance (for native tokens) or get_allowance (for spending approvals). No guidance on prerequisites or exclusions is provided, leaving the context somewhat inferred.

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

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