Skip to main content
Glama

eth_getTransactionByHash

Retrieve detailed transaction information from EVM-compatible blockchains using a transaction hash to analyze transaction data, status, and blockchain activity.

Instructions

Returns the information about a transaction requested by transaction hash

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
txHashYesTransaction hash

Implementation Reference

  • Handler function that takes txHash, calls makeRPCCall to fetch transaction data via RPC, handles not found case, formats response using formatResponse, and returns error if failed.
    async ({ txHash }) => {
      try {
        const result = await makeRPCCall("eth_getTransactionByHash", [txHash]);
        if (!result) {
          return {
            content: [
              {
                type: "text",
                text: `Transaction not found: ${txHash}`,
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: "text",
              text: formatResponse(result, "Transaction Information"),
            },
          ],
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: "text",
              text: `Error: ${error.message}`,
            },
          ],
        };
      }
    },
  • Input schema validation using Zod: requires txHash as string.
    {
      txHash: z.string().describe("Transaction hash"),
    },
  • src/index.ts:350-389 (registration)
    Registration of the tool with MCP server using server.tool(name, description, schema, handler).
    server.tool(
      "eth_getTransactionByHash",
      "Returns the information about a transaction requested by transaction hash",
      {
        txHash: z.string().describe("Transaction hash"),
      },
      async ({ txHash }) => {
        try {
          const result = await makeRPCCall("eth_getTransactionByHash", [txHash]);
          if (!result) {
            return {
              content: [
                {
                  type: "text",
                  text: `Transaction not found: ${txHash}`,
                },
              ],
            };
          }
    
          return {
            content: [
              {
                type: "text",
                text: formatResponse(result, "Transaction Information"),
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: "text",
                text: `Error: ${error.message}`,
              },
            ],
          };
        }
      },
    );
  • Helper function used by the handler to perform the actual RPC call to the Ethereum provider.
    async function makeRPCCall(method: string, params: any[] = []): Promise<any> {
      try {
        const result = await provider.send(method, params);
        return result;
      } catch (error: any) {
        throw new Error(`RPC call failed: ${error.message}`);
      }
    }

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/JamesANZ/evm-mcp'

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