Skip to main content
Glama

eth_getTransactionReceipt

Retrieve transaction receipt details including status, gas used, and logs to verify transaction execution and outcomes on EVM-compatible blockchains.

Instructions

Returns the receipt of a transaction by transaction hash

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
txHashYesTransaction hash

Implementation Reference

  • The complete server.tool registration which defines the handler function for the 'eth_getTransactionReceipt' tool. The handler takes a txHash, calls the RPC method via makeRPCCall, formats the response using formatResponse, and handles errors.
    server.tool(
      "eth_getTransactionReceipt",
      "Returns the receipt of a transaction by transaction hash",
      {
        txHash: z.string().describe("Transaction hash"),
      },
      async ({ txHash }) => {
        try {
          const result = await makeRPCCall("eth_getTransactionReceipt", [txHash]);
          if (!result) {
            return {
              content: [
                {
                  type: "text",
                  text: `Transaction receipt not found: ${txHash}`,
                },
              ],
            };
          }
    
          return {
            content: [
              {
                type: "text",
                text: formatResponse(result, "Transaction Receipt"),
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: "text",
                text: `Error: ${error.message}`,
              },
            ],
          };
        }
      },
    );
  • Input schema for the tool, defining 'txHash' as a required string parameter.
    {
      txHash: z.string().describe("Transaction hash"),
    },
  • Shared helper function makeRPCCall used by the eth_getTransactionReceipt 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}`);
      }
    }
  • Shared helper function formatResponse used to format the tool output in markdown.
    function formatResponse(data: any, title: string): string {
      let result = `**${title}**\n\n`;
    
      if (typeof data === "object" && data !== null) {
        if (Array.isArray(data)) {
          // Handle arrays
          result += `**Count:** ${data.length}\n\n`;
          data.forEach((item, index) => {
            result += `**${index + 1}.**\n`;
            if (typeof item === "object" && item !== null) {
              result += formatObject(item, "  ");
            } else {
              result += `  ${item}\n`;
            }
            result += "\n";
          });
        } else {
          // Handle objects
          result += formatObject(data, "");
        }
      } else {
        result += `${data}\n`;
      }
    
      return result;
    }
    
    // Helper function to format objects recursively
    function formatObject(obj: any, indent: string): string {
      let result = "";
    
      for (const [key, value] of Object.entries(obj)) {
        if (typeof value === "object" && value !== null) {
          if (Array.isArray(value)) {
            result += `${indent}**${key}:** [${value.length} items]\n`;
            if (value.length > 0 && value.length <= 10) {
              value.forEach((item, index) => {
                if (typeof item === "object" && item !== null) {
                  result += `${indent}  ${index}: ${JSON.stringify(item, null, 2).replace(/\n/g, "\n" + indent + "    ")}\n`;
                } else {
                  result += `${indent}  ${index}: ${item}\n`;
                }
              });
            }
          } else {
            result += `${indent}**${key}:**\n`;
            result += formatObject(value, indent + "  ");
          }
        } else {
          result += `${indent}**${key}:** ${value}\n`;
        }
      }
    
      return result;
    }

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