Skip to main content
Glama

get_token_balance

Retrieve the ERC20 token balance for a specific wallet address on any EVM-compatible network using blockchain data. Input wallet and token addresses to get accurate results.

Instructions

Get the balance of an ERC20 token for an address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
networkNoNetwork name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. Supports all EVM-compatible networks. Defaults to Ethereum mainnet.
ownerAddressYesThe wallet address or ENS name to check the balance for (e.g., '0x1234...' or 'vitalik.eth')
tokenAddressYesThe contract address or ENS name of the ERC20 token (e.g., '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' for USDC or 'uniswap.eth')

Implementation Reference

  • Core helper function that executes the ERC20 balance query: resolves ENS if needed, creates viem contract, reads balanceOf, symbol, and decimals in parallel, formats the balance.
    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
        }
      };
    }
  • MCP tool registration for get_token_balance, including Zod input schema, annotations, and thin handler that calls services.getERC20Balance and formats MCP response.
    server.registerTool(
      "get_token_balance",
      {
        description: "Get the ERC20 token balance for an address",
        inputSchema: {
          address: z.string().describe("The wallet address or ENS name"),
          tokenAddress: z.string().describe("The ERC20 token contract address"),
          network: z.string().optional().describe("Network name or chain ID. Defaults to Ethereum mainnet.")
        },
        annotations: {
          title: "Get ERC20 Token Balance",
          readOnlyHint: true,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: true
        }
      },
      async ({ address, tokenAddress, network = "ethereum" }) => {
        try {
          const balance = await services.getERC20Balance(tokenAddress as Address, address as Address, network);
          return {
            content: [{
              type: "text",
              text: JSON.stringify({
                network,
                tokenAddress,
                address,
                balance: {
                  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
          };
        }
      }
    );
  • ERC20 ABI schema used by the balance helper for contract reads (symbol, decimals, 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;
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Get' implies a read-only operation, it doesn't specify whether this requires network access, has rate limits, returns cached or real-time data, or what format the balance is returned in. The description is minimal and lacks important operational context.

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 communicates the core purpose without any wasted words. It's appropriately sized for a straightforward tool and gets directly to the point with clear subject-verb-object structure.

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?

For a tool with no annotations and no output schema, the description is insufficient. It doesn't explain what format the balance is returned in (wei, ether, decimal), whether it supports ENS resolution for both addresses, error conditions, or how it differs from the similar 'get_erc20_balance' sibling. The minimal description leaves too many operational questions unanswered.

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 fully documents all three parameters. The description doesn't add any additional meaning beyond what's in the schema descriptions - it doesn't explain parameter relationships, default behaviors, or provide examples of valid inputs beyond what the schema already specifies.

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 'Get' and the resource 'balance of an ERC20 token for an address', making the purpose immediately understandable. It distinguishes from general 'get_balance' by specifying ERC20 tokens, but doesn't explicitly differentiate from the sibling 'get_erc20_balance' tool which appears to serve a similar function.

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 like 'get_erc20_balance' or 'get_balance'. It doesn't mention prerequisites, error conditions, or when this specific tool is preferred over similar siblings in the toolset.

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

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

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