Skip to main content
Glama

get-token-transfers

Retrieve ERC20 token transfer history for any Ethereum address to track transactions and monitor token movements on the blockchain.

Instructions

Get ERC20 token transfers for an Ethereum address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesEthereum address (0x format)
limitNoNumber of transfers to return (max 100)

Implementation Reference

  • Core implementation of getTokenTransfers that fetches and formats ERC20 token transfer data from the Etherscan API.
    async getTokenTransfers(address: string, limit: number = 10): Promise<TokenTransfer[]> {
      try {
        const validAddress = ethers.getAddress(address);
        
        // Get ERC20 token transfers
        const result = await fetch(
          `https://api.etherscan.io/api?module=account&action=tokentx&address=${validAddress}&page=1&offset=${limit}&sort=desc&apikey=${this.provider.apiKey}`
        );
        
        const data = await result.json();
        
        if (data.status !== "1" || !data.result) {
          throw new Error(data.message || "Failed to fetch token transfers");
        }
    
        // Format the results
        return data.result.slice(0, limit).map((tx: any) => ({
          token: tx.contractAddress,
          tokenName: tx.tokenName,
          tokenSymbol: tx.tokenSymbol,
          from: tx.from,
          to: tx.to,
          value: ethers.formatUnits(tx.value, parseInt(tx.tokenDecimal)),
          timestamp: parseInt(tx.timeStamp) || 0,
          blockNumber: parseInt(tx.blockNumber) || 0
        }));
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Failed to get token transfers: ${error.message}`);
        }
        throw error;
      }
    }
  • MCP tool dispatch handler for 'get-token-transfers' that validates input, calls the service, formats output, and returns MCP response.
    if (name === "get-token-transfers") {
      try {
        const { address, limit } = TokenTransferSchema.parse(args);
        const transfers = await etherscanService.getTokenTransfers(address, limit);
        const formattedTransfers = transfers.map(tx => {
          const date = new Date(tx.timestamp * 1000).toLocaleString();
          return `Block ${tx.blockNumber} (${date}):\n` +
                 `Token: ${tx.tokenName} (${tx.tokenSymbol})\n` +
                 `From: ${tx.from}\n` +
                 `To: ${tx.to}\n` +
                 `Value: ${tx.value}\n` +
                 `Contract: ${tx.token}\n` +
                 `---`;
        }).join('\n');
    
        const response = transfers.length > 0
          ? `Recent token transfers for ${address}:\n\n${formattedTransfers}`
          : `No token transfers found for ${address}`;
    
        return {
          content: [{ type: "text", text: response }],
        };
      } catch (error) {
        if (error instanceof z.ZodError) {
          throw new Error(`Invalid input: ${error.errors.map(e => e.message).join(", ")}`);
        }
        throw error;
      }
    }
  • src/server.ts:91-111 (registration)
    Registers the 'get-token-transfers' tool in the MCP server's tool list with description and input schema.
    {
      name: "get-token-transfers",
      description: "Get ERC20 token transfers for an Ethereum address",
      inputSchema: {
        type: "object",
        properties: {
          address: {
            type: "string",
            description: "Ethereum address (0x format)",
            pattern: "^0x[a-fA-F0-9]{40}$"
          },
          limit: {
            type: "number",
            description: "Number of transfers to return (max 100)",
            minimum: 1,
            maximum: 100
          },
        },
        required: ["address"],
      },
    },
  • Zod schema for validating input parameters (address and optional limit) for the get-token-transfers tool.
    const TokenTransferSchema = z.object({
      address: z.string().regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address format'),
      limit: z.number().min(1).max(100).optional(),
    });
  • TypeScript interface defining the structure of token transfer data returned by the service.
    export interface TokenTransfer {
      token: string;
      tokenName: string;
      tokenSymbol: string;
      from: string;
      to: string;
      value: string;
      timestamp: number;
      blockNumber: number;
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

C2.9/5.0
Behavior2/5

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

No annotations are present, and the description fails to disclose important behavioral details such as pagination, ordering, or whether the result includes all transfers or only recent ones.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence and front-loaded, but lacks important context. It is not overly verbose, but could be more informative.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simple nature of the tool and the presence of schema descriptions for both parameters, the description is minimally adequate. However, it does not cover aspects like return format or usage constraints.

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 score of 3 applies. The description adds no additional meaning beyond the already documented parameters.

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 that the tool retrieves ERC20 token transfers for a given Ethereum address. It is specific about the resource and action, but does not differentiate from siblings like get-transactions.

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 such as get-transactions or check-balance. The description lacks context for appropriate usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.