Skip to main content
Glama
EmanuelJr
by EmanuelJr

fetch_token_balance

Retrieve token balances for specific wallets on EVM chains by providing token address, chain ID, and wallet address.

Instructions

Get the balance of a token

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenAddressYes
chainIdYes
walletAddressYes

Implementation Reference

  • The main asynchronous handler function that fetches the ERC20 token balance for a given wallet on a specific chain using viem library.
    export const fetchTokenBalance = async (options: FetchTokenBalanceOptions) => {
      const { tokenAddress, chainId, walletAddress } = options;
    
      const chain = getChainById(chainId);
      const client = createClient(chain);
    
      const contract = getContract({
        address: tokenAddress as `0x${string}`,
        abi: erc20Abi,
        client,
      });
    
      const [balance, decimals] = await Promise.all([
        contract.read.balanceOf([walletAddress as `0x${string}`]),
        contract.read.decimals(),
      ]);
    
      return {
        balance: balance.toString(),
        formattedBalance: formatUnits(balance, decimals),
      };
    };
  • Zod schema defining the input parameters: tokenAddress, chainId, and walletAddress with validation.
    export const FetchTokenBalanceSchema = z.object({
      tokenAddress: z.string().startsWith("0x"),
      chainId: z.number(),
      walletAddress: z.string().startsWith("0x"),
    });
  • src/index.ts:46-49 (registration)
    Registration of the tool in the ListToolsRequestSchema handler, specifying name, description, and input schema.
      name: "fetch_token_balance",
      description: "Get the balance of a token",
      inputSchema: z.toJSONSchema(FetchTokenBalanceSchema),
    },
  • src/index.ts:122-140 (registration)
    Dispatch handler in the CallToolRequestSchema switch statement that parses arguments, calls fetchTokenBalance, and formats the response.
    case "fetch_token_balance": {
      const args = FetchTokenBalanceSchema.parse(request.params.arguments);
      const result = await fetchTokenBalance(args);
    
      return {
        content: [
          {
            type: "text",
            text: result.balance,
            description: "The balance of the token",
          },
          {
            type: "text",
            text: result.formattedBalance,
            description: "The formatted balance of the token",
          },
        ],
      };
    }
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. 'Get the balance' implies a read-only operation, but it doesn't specify whether this requires authentication, has rate limits, returns cached vs real-time data, or what format the balance comes in. For a 3-parameter tool with zero annotation coverage, this is insufficient.

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 with zero wasted words. It's appropriately sized for a straightforward tool and front-loads the core purpose immediately.

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 3 undocumented parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., numeric balance, formatted string, error conditions) or provide enough context for reliable agent usage beyond the basic purpose.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning none of the 3 parameters are documented in the schema. The description doesn't mention any parameters at all, failing to compensate for this gap. The agent must infer parameter meanings from names like 'tokenAddress' and 'chainId' without any semantic guidance.

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 a token', making the purpose immediately understandable. However, it doesn't differentiate this tool from its sibling 'fetch_balance', which appears to be a similar balance-fetching operation, 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 like 'fetch_balance' or 'fetch_quote'. There's no mention of prerequisites, context, or exclusions, leaving the agent to guess based on tool names alone.

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/EmanuelJr/web3-mcp-server'

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