# Eth.blockNumber

Returns the number of the most recent block the node has.

## Usage

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

const blockNumber = await Eth.blockNumber().pipe(
  Effect.provide(Transport.http("http://127.0.0.1:8545")),
  Effect.provide(FetchHttpClient.layer),
  Effect.runPromise,
);
// 0n on a fresh anvil
```

The call works over every [transport](https://ethect.dev/guides/transports/). The examples below leave the
transport out.

### Count confirmations

Subtract the block a transaction was mined in from the head to know how many blocks confirm
it.

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

const hash = "0xa23b52004fe574000765fbe20a311b2785a318c9dbe6b0bf6a4c1f8936f57ff3";

const confirmations = Effect.gen(function* () {
  const receipt = yield* Eth.getTransactionReceipt(hash);
  if (receipt === null) return 0n;
  const head = yield* Eth.blockNumber();
  return head - receipt.blockNumber + 1n;
});
```

A transaction mined in block `1n` has `3n` confirmations when the head is `3n`.

### Read the block itself

To read the latest block you do not need its number first: name it with the `"latest"` tag.

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

const latest = Eth.getBlockByNumber("latest", false).pipe(
  Effect.map((block) => block?.timestamp),
);
```

## Returns

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

The number of the block at the head of the chain, as this node sees it.

## Parameters

None.

## Behavior

- **A `bigint`.** The node answers `"0x6"` and you get `6n`. Every block number in ethect is a
  `bigint`. See [values on the wire](https://ethect.dev/rpc/guides/values/).
- **One request per call.** To be told about each new block instead of asking, use
  [`Eth.subscribe.newHeads`](https://ethect.dev/rpc/eth/subscribe/new-heads/).

## JSON-RPC method

`eth_blockNumber`
