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
| Name | Required | Description | Default |
|---|---|---|---|
| txHash | Yes | Transaction hash |
Implementation Reference
- src/index.ts:356-388 (handler)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}`, }, ], }; } },
- src/index.ts:353-355 (schema)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}`, }, ], }; } }, );
- src/index.ts:89-96 (helper)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}`); } }