# 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.

## Usage

```ts
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](https://ethect.dev/guides/transports/). The examples below leave the
transport out.

### Find what reverted

One request gives the outcome of the whole block.

```ts
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);
});
```

### Every log of a block

Each receipt carries the logs its transaction emitted.

```ts
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);
});
```

### By block hash

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

```ts
import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";

const receipts = Eth.getBlockReceipts({
  blockHash: "0xe5178f52e018186949d9fe9168c6011820f9c6bd449a93dbb07c09dfc0af3dfa",
});
```

## Returns

[`Effect<ReadonlyArray<Receipt.Receipt> | null, Method.Error, Transport>`](https://ethect.dev/rpc/method/#calling-a-method)

One [`Receipt`](https://ethect.dev/rpc/types/receipt/) per transaction, or `null` when the node does not
have the block.

## Parameters

### block

- **Type:** [`BlockId.BlockId`](https://ethect.dev/rpc/types/block-id/)

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

```ts
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)}` }),
]);
```

## Behavior

- **`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`](https://ethect.dev/rpc/eth/get-transaction-receipt/) per transaction.

## Errors

The three [errors](https://ethect.dev/reference/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 |

## JSON-RPC method

`eth_getBlockReceipts`
