# Withdrawal

A validator withdrawal, pushed into a block by the consensus layer since the Shanghai fork
(EIP-4895).

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

const withdrawn = Effect.gen(function* () {
  const block = yield* Eth.getBlockByNumber("latest", false);
  if (block === null) return 0n;
  // block.withdrawals: ReadonlyArray<Withdrawal.Withdrawal> | undefined
  const gwei = (block.withdrawals ?? []).reduce((sum, { amount }) => sum + amount, 0n);
  return gwei * 10n ** 9n; // in wei
});
```

## Schemas

| Schema | Type | Describes | Used by |
| --- | --- | --- | --- |
| `Withdrawal.schema` | `Withdrawal.Withdrawal` | one withdrawal | `withdrawals` of a [`Block`](https://ethect.dev/rpc/types/block/) and of a [`BlockOverride`](https://ethect.dev/rpc/types/block-override/) |

## Fields

| Field | Type | Notes |
| --- | --- | --- |
| `index` | `bigint` | the number of the withdrawal, counted over the whole chain |
| `validatorIndex` | `bigint` | the validator the withdrawal comes from |
| `address` | `Address` | the account that receives the ether |
| `amount` | `bigint` | in gwei, not in wei |

## Behavior

- **`amount` is in gwei.** A balance and the `value` of a transaction are in wei. Multiply the
  amount by `10n ** 9n` to compare it with them.
- **Not a transaction.** A withdrawal credits its `address` without a transaction, a receipt or
  a log. It only appears in the `withdrawals` of its block.
- **`withdrawals` can be absent.** A block from before Shanghai has no `withdrawals` key. A
  later block with none has an empty array, as every block of a fresh anvil does.
