Skip to main content
Glama
EmanuelJr
by EmanuelJr

fetch_balance

Retrieve wallet balances from EVM chains by providing a wallet address and chain ID to check cryptocurrency holdings.

Instructions

Get the balance of a wallet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
walletAddressYes
chainIdYes

Implementation Reference

  • The main handler function that fetches the balance for a given wallet address on a specified chain using viem client.
    export const fetchBalance = async (options: FetchBalanceOptions) => {
      const { walletAddress, chainId } = options;
    
      const chain = getChainById(chainId);
      const client = createClient(chain);
    
      const balance = await client.getBalance({
        address: walletAddress as `0x${string}`,
      });
    
      return {
        balance: balance.toString(),
        formattedBalance: formatUnits(balance, chain.nativeCurrency.decimals),
      };
    };
  • Zod schema defining the input options for the fetch_balance tool: walletAddress and chainId.
    export const FetchBalanceSchema = z.object({
      walletAddress: z.string().startsWith("0x"),
      chainId: z.number(),
    });
  • src/index.ts:36-38 (registration)
    Tool registration in the listTools handler, specifying name, description, and input schema.
    name: "fetch_balance",
    description: "Get the balance of a wallet",
    inputSchema: z.toJSONSchema(FetchBalanceSchema),
  • src/index.ts:84-102 (registration)
    Dispatch handler in callToolRequest that parses arguments with schema and invokes the fetchBalance function, formatting the response.
    case "fetch_balance": {
      const args = FetchBalanceSchema.parse(request.params.arguments);
      const result = await fetchBalance(args);
    
      return {
        content: [
          {
            type: "text",
            text: result.balance,
            description: "The balance of the wallet",
          },
          {
            type: "text",
            text: result.formattedBalance,
            description: "The formatted balance of the wallet",
          },
        ],
      };
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states a read operation ('Get'), implying non-destructive behavior, but lacks details on permissions, rate limits, error handling, or return format. This is inadequate for a tool with zero 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 unnecessary 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 (2 required parameters), no annotations, no output schema, and 0% schema coverage, the description is incomplete. It doesn't address parameter meanings, behavioral traits, or output details, leaving significant gaps for effective tool use.

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%, so the schema provides no parameter details. The description mentions 'wallet' but doesn't explain the parameters 'walletAddress' or 'chainId', their formats, or purposes. It adds minimal value beyond the schema, failing to compensate for the coverage gap.

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 action ('Get') and resource ('balance of a wallet'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'fetch_token_balance' or 'read_contract', which might also retrieve balance-related information, so it doesn't reach the highest 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. There are sibling tools like 'fetch_token_balance' that might handle similar queries, but no explicit comparisons or context for selection are given, leaving usage unclear.

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