Eth.getTransactionByHash
Returns a transaction by its hash, pending or mined, or null when the node does not know it.
import { Effect } from "effect";import { FetchHttpClient } from "effect/http";import { Transport } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const transaction = await Eth.getTransactionByHash( "0xa23b52004fe574000765fbe20a311b2785a318c9dbe6b0bf6a4c1f8936f57ff3",).pipe( Effect.provide(Transport.http("http://127.0.0.1:8545")), Effect.provide(FetchHttpClient.layer), Effect.runPromise,);// transaction?.type: "eip1559"// transaction?.value: 1n// transaction?.blockNumber: 1nThe call works over every transport. The examples below leave the transport out.
Pending or mined
Section titled “Pending or mined”A pending transaction has no place in the chain yet: its blockNumber is null.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
const hash = "0xa23b52004fe574000765fbe20a311b2785a318c9dbe6b0bf6a4c1f8936f57ff3";
const state = Effect.gen(function* () { const transaction = yield* Eth.getTransactionByHash(hash); if (transaction === null) return "unknown"; if (transaction.blockNumber === null) return "pending"; return `mined in block ${transaction.blockNumber}`;});Read the fields of one type
Section titled “Read the fields of one type”The result is a union of transaction types. Compare type to reach the fields of one.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
const hash = "0xa23b52004fe574000765fbe20a311b2785a318c9dbe6b0bf6a4c1f8936f57ff3";
const feeCap = Effect.gen(function* () { const transaction = yield* Eth.getTransactionByHash(hash); if (transaction === null) return null; return transaction.type === "eip1559" ? transaction.maxFeePerGas // 2000000000n : null;});The Transaction page lists the fields of every type.
A contract creation
Section titled “A contract creation”A transaction that creates a contract has no recipient: to is null, and input is the
code that ran to create it.
import { Effect } from "effect";import { type Hash } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const isCreation = (hash: Hash.Hash) => Eth.getTransactionByHash(hash).pipe( Effect.map((transaction) => // null when the node does not know the transaction transaction === null ? null : transaction.to === null, ), );Returns
Section titled “Returns”Effect<Transaction.Transaction | null, Method.Error, Transport>
A Transaction, or null when the node does not know the
hash.
Parameters
Section titled “Parameters”- Type:
Hash.Hash
The hash of the transaction: 32 bytes of hex.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
const transaction = Eth.getTransactionByHash( "0xa23b52004fe574000765fbe20a311b2785a318c9dbe6b0bf6a4c1f8936f57ff3",);Behavior
Section titled “Behavior”nullfor a hash the node does not know. That covers a hash that never existed and a transaction the node dropped from its pool.nullfields while pending.blockHash,blockNumberandtransactionIndexarenulluntil the transaction is mined.- Found does not mean succeeded. A transaction that reverted is returned like any other.
Its outcome is the
statusof its receipt. - No receipt data. Gas used, logs and the address of a created contract are on the receipt.
Errors
Section titled “Errors”The three errors every method can fail with. The case specific to this method:
| Error | Reason | When |
|---|---|---|
CodecError |
on: "params" |
the hash is not 32 bytes of hex: nothing is sent |
JSON-RPC method
Section titled “JSON-RPC method”eth_getTransactionByHash