Skip to main content
Glama
5ajaki

MCP Etherscan Server

by 5ajaki

get-transactions

Retrieve recent Ethereum blockchain transactions for any address to monitor activity and track transfers.

Instructions

Get recent transactions for an Ethereum address

Input Schema

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

Implementation Reference

  • Handler for the 'get-transactions' tool: validates input with TransactionHistorySchema, calls etherscanService.getTransactionHistory, formats transactions into a readable text response.
    if (name === "get-transactions") {
      try {
        const { address, limit } = TransactionHistorySchema.parse(args);
        const transactions = await etherscanService.getTransactionHistory(
          address,
          limit
        );
        const formattedTransactions = transactions
          .map((tx) => {
            const date = new Date(tx.timestamp * 1000).toLocaleString();
            return (
              `Block ${tx.blockNumber} (${date}):\n` +
              `Hash: ${tx.hash}\n` +
              `From: ${tx.from}\n` +
              `To: ${tx.to}\n` +
              `Value: ${tx.value} ETH\n` +
              `---`
            );
          })
          .join("\n");
    
        const response =
          transactions.length > 0
            ? `Recent transactions for ${address}:\n\n${formattedTransactions}`
            : `No transactions 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;
      }
    }
  • Zod schema for validating input parameters (address and optional limit) for the get-transactions tool.
    const TransactionHistorySchema = z.object({
      address: z
        .string()
        .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format"),
      limit: z.number().min(1).max(100).optional(),
    });
  • src/server.ts:81-101 (registration)
    Tool registration in listTools response, defining name, description, and input schema.
    {
      name: "get-transactions",
      description: "Get recent transactions 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 transactions to return (max 100)",
            minimum: 1,
            maximum: 100,
          },
        },
        required: ["address"],
      },
    },
  • EtherscanService.getTransactionHistory: fetches transaction list from Etherscan API via fetch, validates address, formats into Transaction interface objects.
    async getTransactionHistory(address: string, limit: number = 10): Promise<Transaction[]> {
      try {
        // Validate the address
        const validAddress = ethers.getAddress(address);
        
        // Get transactions directly from Etherscan API
        const result = await fetch(
          `https://api.etherscan.io/api?module=account&action=txlist&address=${validAddress}&startblock=0&endblock=99999999&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 transactions");
        }
    
        // Format the results
        return data.result.slice(0, limit).map((tx: any) => ({
          hash: tx.hash,
          from: tx.from,
          to: tx.to || 'Contract Creation',
          value: ethers.formatEther(tx.value),
          timestamp: parseInt(tx.timeStamp) || 0,
          blockNumber: parseInt(tx.blockNumber) || 0
        }));
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Failed to get transaction history: ${error.message}`);
        }
        throw error;
      }
    }
  • TypeScript interface defining the structure of a Transaction object returned by getTransactionHistory.
    export interface Transaction {
      hash: string;
      from: string;
      to: string;
      value: string;
      timestamp: number;
      blockNumber: number;
    }
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 mentions 'recent transactions' but doesn't specify time frames, pagination, rate limits, authentication needs, or error handling. For a read operation with potential complexity, this leaves significant gaps in understanding how the tool behaves beyond basic input-output.

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 front-loads the core purpose without any wasted words. It's appropriately sized for a simple tool and gets straight to the point, 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 no annotations and no output schema, the description is incomplete for a tool that fetches transactions. It lacks details on return format (e.g., list structure, fields included), error cases, or behavioral traits like rate limits. For a read operation with potential data volume, more context is needed to use it effectively.

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?

The input schema has 100% description coverage, clearly documenting both parameters ('address' and 'limit') with formats and constraints. The description adds no additional parameter semantics beyond implying 'recent' for transactions, which is vague and not parameter-specific. Baseline 3 is appropriate as 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 action ('Get') and resource ('recent transactions for an Ethereum address'), making the purpose immediately understandable. It doesn't explicitly distinguish from sibling tools like 'get-token-transfers', which might be a similar query, but it's specific enough to understand the core function.

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 'get-token-transfers' or 'check-balance'. It states what it does but offers no context about appropriate scenarios, prerequisites, or exclusions, leaving the agent to infer usage 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/5ajaki/mcp-etherscan-server'

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