Skip to main content
Glama

get_erc20_balance

Retrieve ERC20 token balances for a specific address on supported networks, including BSC, Ethereum, and others, by providing the token contract address and network details.

Instructions

Get ERC20 token balance for an address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesThe address to check balance for
networkNoNetwork name (e.g. 'bsc', 'opbnb', 'ethereum', 'base', etc.) or chain ID. Supports others main popular networks. Defaults to BSC mainnet.bsc
tokenAddressYesThe ERC20 token contract address

Implementation Reference

  • The core handler function that resolves addresses, fetches ERC20 balance, symbol, and decimals from the blockchain, and formats the result.
    export async function getERC20Balance(
      tokenAddressOrEns: string,
      ownerAddressOrEns: string,
      network = "ethereum"
    ): Promise<{
      raw: bigint
      formatted: string
      symbol: string
      decimals: number
      network: string
      tokenAddress: Address
      ownerAddress: Address
    }> {
      // 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: ERC20_ABI,
        client: publicClient
      })
    
      const [balance, symbol, decimals] = await Promise.all([
        contract.read.balanceOf([ownerAddress]) as Promise<bigint>,
        contract.read.symbol() as Promise<string>,
        contract.read.decimals() as Promise<number>
      ])
    
      return {
        raw: balance,
        formatted: formatUnits(balance, decimals),
        symbol,
        decimals,
        network,
        tokenAddress,
        ownerAddress
      }
    }
  • Registers the 'get_erc20_balance' MCP tool, including input schema validation with Zod and a wrapper handler that calls the core getERC20Balance service.
    server.tool(
      "get_erc20_balance",
      "Get ERC20 token balance for an address",
      {
        tokenAddress: z.string().describe("The ERC20 token contract address"),
        address: z.string().describe("The address to check balance for"),
        network: defaultNetworkParam,
        privateKey: privateKeyParam
      },
      async ({ network, tokenAddress, address, privateKey }) => {
        try {
          const res = await services.getERC20Balance(
            tokenAddress as Address,
            address || privateKeyToAccount(privateKey as Hex).address,
            network
          )
    
          return mcpToolRes.success(res)
        } catch (error) {
          return mcpToolRes.error(error, "fetching ERC20 token balance")
        }
      }
    )
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 action ('Get') but doesn't describe traits like whether this is a read-only operation (implied but not explicit), potential rate limits, error conditions, or what the return value looks like (e.g., balance in token units). This is inadequate for a tool with no annotation coverage.

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 any wasted words. It's 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.

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 operations, no annotations, and no output schema, the description is incomplete. It doesn't explain the return format (e.g., numeric balance, decimals), error handling, or behavioral traits like network support details. For a tool with 3 parameters and no structured output, more context is needed.

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 (address, network, tokenAddress) with clear descriptions. The description doesn't add any additional meaning beyond what's in the schema, such as explaining parameter interactions or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.

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 resource ('ERC20 token balance for an address'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_native_balance' or 'get_erc1155_balance', which would require mentioning it's specifically for ERC20 tokens (though implied by the name).

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. For example, it doesn't specify to use 'get_native_balance' for native tokens or 'get_erc1155_balance' for ERC1155 tokens, nor does it mention prerequisites like needing a token contract address. This leaves the agent without contextual 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

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/bnb-chain/bnbchain-mcp'

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