Skip to main content
Glama

get_token_balances

Retrieve token balances for a wallet address across supported networks. Check if a wallet holds ETH, USDC, or other tokens on Ethereum, Base, Optimism, Arbitrum, Polygon, BNB, Avalanche, and Zora.

Instructions

Spot token balances only (no DeFi positions). Use when the question is specifically about token holdings: 'does this wallet hold ETH?', 'how much USDC is on Base?'

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesWallet address or ENS name
networksNoNetworks to filter by. Supported: ethereum, base, optimism, arbitrum, polygon, bnb, avalanche, zora. Omit for all networks.

Implementation Reference

  • src/server.ts:68-90 (registration)
    Tool registration for 'get_token_balances' via server.registerTool(). Delegates to fetchTokenBalances().
    // ── Tool: get_token_balances ─────────────────────────────────────────────────
    
    server.registerTool(
      "get_token_balances",
      {
        description:
          "Spot token balances only (no DeFi positions). Use when the question is specifically about token holdings: 'does this wallet hold ETH?', 'how much USDC is on Base?'",
        inputSchema: {
          address: z.string().describe("Wallet address or ENS name"),
          networks: networksSchema,
        },
      },
      async ({ address, networks }) => {
        try {
          const result = await fetchTokenBalances(apiKey, address, resolveChainIds(networks));
          return {
            content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
          };
        } catch (err) {
          return errorResponse(err);
        }
      },
    );
  • The actual handler function fetchTokenBalances() that executes the logic: queries Zapper GraphQL API for token balances and returns typed TokenBalancesResult.
    export async function fetchTokenBalances(
      apiKey: string,
      address: string,
      chainIds?: number[],
    ): Promise<TokenBalancesResult> {
      const data = (await gql(apiKey, TOKEN_BALANCES_QUERY, {
        addresses: [address],
        chainIds: chainIds ?? null,
      })) as { portfolioV2: { tokenBalances: { totalBalanceUSD: number; byToken: { edges: Array<{ node: GqlTokenNode }> } } } };
    
      const tb = data.portfolioV2.tokenBalances;
      return {
        totalUSD: tb.totalBalanceUSD ?? 0,
        tokens: tb.byToken.edges.map(({ node }) => parseTokenNode(node)),
      };
    }
  • Type definitions: TokenBalance interface and TokenBalancesResult interface defining the output shape.
    export interface TokenBalance {
      symbol: string;
      name: string;
      balance: number;
      balanceUSD: number;
      price: number;
      network: string;
    }
    
    export interface TokenBalancesResult {
      totalUSD: number;
      tokens: TokenBalance[];
    }
  • Input schema for the tool: address (string) and optional networks (array of strings).
      "Spot token balances only (no DeFi positions). Use when the question is specifically about token holdings: 'does this wallet hold ETH?', 'how much USDC is on Base?'",
    inputSchema: {
      address: z.string().describe("Wallet address or ENS name"),
      networks: networksSchema,
    },
  • The TOKEN_BALANCES_QUERY GraphQL string used by fetchTokenBalances to query the Zapper API.
    const TOKEN_BALANCES_QUERY = `
      query TokenBalances($addresses: [Address!]!, $chainIds: [Int!]) {
        portfolioV2(addresses: $addresses, chainIds: $chainIds) {
          tokenBalances {
            totalBalanceUSD
            byToken(first: 50) {
              edges {
                node {
                  symbol
                  name
                  balance
                  balanceUSD
                  price
                  network { name }
                }
              }
            }
          }
        }
      }
    `;
Behavior3/5

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

With no annotations, the description carries full burden. It discloses the scope (spot tokens only) but does not mention any other behavioral traits such as rate limits, authentication requirements, or response format. Acceptable but could be more comprehensive.

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?

Two short, front-loaded sentences with no redundant information. Every word contributes to clarity and utility.

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 has only two parameters and no output schema, the description is reasonably complete: it states scope, use cases, and exclusions. It could briefly hint at output structure, but that is not critical for this simple tool.

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 coverage is 100%, so baseline is 3. The description adds minor value by providing usage examples but does not elaborate on parameter semantics beyond what the schema already provides.

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 tool returns 'spot token balances only' and explicitly excludes DeFi positions, distinguishing it from siblings like get_app_positions. It also provides specific example queries, making the purpose unambiguous.

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

Usage Guidelines4/5

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

The description explicitly says 'Use when the question is specifically about token holdings' and gives concrete examples. It implies when not to use (DeFi positions) but does not directly name alternative tools for that case. Still, the guidance is clear and helpful.

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/mehdi-loup/zapper-mcp'

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