Skip to content

Eth.getBlockReceipts

Returns the receipts of every transaction in a block, in the order of the block, or null when the node does not have the block.

import { Effect } from "effect";
import { FetchHttpClient } from "effect/http";
import { Transport } from "@ethect/core";
import { Eth } from "@ethect/core/rpc";
const receipts = await Eth.getBlockReceipts("latest").pipe(
Effect.provide(Transport.http("http://127.0.0.1:8545")),
Effect.provide(FetchHttpClient.layer),
Effect.runPromise,
);
// receipts?.map((receipt) => receipt.status): ["success", "success", "reverted"]

The call works over every transport. The examples below leave the transport out.

One request gives the outcome of the whole block.

import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";
const reverted = Effect.gen(function* () {
const receipts = yield* Eth.getBlockReceipts("latest");
if (receipts === null) return [];
return receipts
.filter((receipt) => receipt.status === "reverted")
.map((receipt) => receipt.transactionHash);
});

Each receipt carries the logs its transaction emitted.

import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";
const logs = Effect.gen(function* () {
const receipts = yield* Eth.getBlockReceipts(19_000_000n);
if (receipts === null) return [];
return receipts.flatMap((receipt) => receipt.logs);
});

Name the block by its hash to read the receipts of that exact block.

import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";
const receipts = Eth.getBlockReceipts({
blockHash: "0xe5178f52e018186949d9fe9168c6011820f9c6bd449a93dbb07c09dfc0af3dfa",
});

Effect<ReadonlyArray<Receipt.Receipt> | null, Method.Error, Transport>

One Receipt per transaction, or null when the node does not have the block.

The block: a number, a tag, or an object that names the block by number or by hash. It is required.

import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";
const receipts = Effect.all([
Eth.getBlockReceipts("finalized"),
Eth.getBlockReceipts(19_000_000n),
Eth.getBlockReceipts({ blockHash: `0x${"ab".repeat(32)}` }),
]);
  • null, not an error. A number above the head and a hash no block has both give null.
  • An empty block gives []. The block exists and has no transaction.
  • In the order of the block. The receipt at position i has transactionIndex equal to i.
  • One request for the block. It replaces one Eth.getTransactionReceipt per transaction.

The three errors every method can fail with. The case specific to this method:

Error Reason When
CodecError on: "params" the block number is negative: nothing is sent

eth_getBlockReceipts