# BlockAccessList

What a block read and wrote, account by account, as `eth_getBlockAccessList` returns it
(EIP-7928).

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

const written = Effect.gen(function* () {
  const accessList = yield* Eth.getBlockAccessList("latest");
  if (accessList === null) return [];
  // accessList: BlockAccessList.BlockAccessList
  return accessList
    .filter((account) => account.storageChanges.length > 0)
    .map((account) => account.address);
});
```

## Schemas

| Schema | Type | Describes | Returned by |
| --- | --- | --- | --- |
| `BlockAccessList.schema` | `BlockAccessList.BlockAccessList` | the access list of a block: an array of `BlockAccessList.Account` | [`Eth.getBlockAccessList`](https://ethect.dev/rpc/eth/block-details/#getblockaccesslist) |
| `BlockAccessList.accountSchema` | `BlockAccessList.Account` | what a block did to one account | each entry of the array |

`BlockAccessList.Account` is not the [`Account`](https://ethect.dev/rpc/types/account/) module: that one is
the state of an account, this one is what a block changed in it.

## Fields

`BlockAccessList.Account`.

| Field | Type | Notes |
| --- | --- | --- |
| `address` | `Address` | the account |
| `storageChanges` | `ReadonlyArray<{ key: Hex; changes: ReadonlyArray<{ index: number; value: Hex }> }>` | each slot the block wrote, with every value it took, as 32-byte words |
| `storageReads` | `ReadonlyArray<Hex>` | the slots the block read without writing them, as 32-byte words |
| `balanceChanges` | `ReadonlyArray<{ index: number; value: bigint }>` | each balance the account had, in wei |
| `nonceChanges` | `ReadonlyArray<{ index: number; value: number }>` | each nonce the account had |
| `codeChanges` | `ReadonlyArray<{ index: number; code: Hex }>` | each code the account was given |

Every change carries an `index`: `0` for the system calls that open the block, then each
transaction from `1`, in the order of the block.

## Behavior

- **`null` before the Amsterdam fork.** A block from before the fork has no access list, and
  [`Eth.getBlockAccessList`](https://ethect.dev/rpc/eth/block-details/#getblockaccesslist) returns `null`
  for it. That is every block of an anvil started without `--hardfork amsterdam`.
- **`index` starts at `1` for transactions.** The changes of the first transaction of a block
  have the index `1`. The index `0` holds what the system calls changed before it.
- **Slots and values are 32 bytes.** A node may send them short (`"0x7"`): they are read as
  32-byte words, so a slot compares with one from another block.
- **An account can have five empty arrays.** An account the block only touched is listed with
  nothing in any of them.
- **Numbers.** An `index` and a nonce are `number`. A balance is a `bigint`. See
  [values on the wire](https://ethect.dev/rpc/guides/values/).

### On anvil

anvil 1.9 started with `--hardfork amsterdam` serves the method, and sends storage slots and
values in a short form. This is what it answers for a contract whose slot `0` was set to `7` by
the first transaction of the block:

```json
{
  "address": "0x5fbdb2315678afecb367f032d93f642f64180aa3",
  "storageChanges": [
    { "key": "0x0", "changes": [{ "index": "0x1", "value": "0x7" }] }
  ],
  "storageReads": [],
  "balanceChanges": [],
  "nonceChanges": [{ "index": "0x1", "value": "0x1" }],
  "codeChanges": []
}
```

Decoded, `key` is `"0x0000…0000"` and the value `"0x0000…0007"`, both 32 bytes, and each
`index` is the number `1`.
