# AccessList

An EIP-2930 access list, which names the addresses and storage slots a transaction declares it touches, and the result of Eth.createAccessList.

An EIP-2930 access list: the addresses and storage slots a transaction declares it touches. The
module also has the result of [`Eth.createAccessList`](https://ethect.dev/rpc/eth/create-access-list/).

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

const FROM = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const TO = Address.makeUnsafe("0x5FbDB2315678afecb367f032d93F642f64180aa3");

const sent = Effect.gen(function* () {
  // a contract that stores the 32-byte word it is called with
  const request = { from: FROM, to: TO, data: `0x${"00".repeat(31)}05` as const };
  const { accessList } = yield* Eth.createAccessList(request, "latest");
  // accessList: AccessList.AccessList
  return yield* Eth.sendTransaction({ ...request, accessList });
});
```

## Schemas

| Schema | Type | Describes | Used by |
| --- | --- | --- | --- |
| `AccessList.schema` | `AccessList.AccessList` | an access list | the `accessList` of a [`TransactionRequest`](https://ethect.dev/rpc/types/transaction-request/) and of a [`Transaction`](https://ethect.dev/rpc/types/transaction/) |
| `AccessList.entrySchema` | `AccessList.Entry` | one account of an access list, with its storage slots | each entry of an `AccessList.AccessList` |
| `AccessList.resultSchema` | `AccessList.Result` | an access list with the gas it leads to | [`Eth.createAccessList`](https://ethect.dev/rpc/eth/create-access-list/) |

## Fields

`AccessList.AccessList` is a `ReadonlyArray` of `AccessList.Entry`, one per address.

| Field | Type | Notes |
| --- | --- | --- |
| `address` | `Address` | an account or a contract the transaction touches |
| `storageKeys` | `ReadonlyArray<Hash>` | the storage slots it touches there, 32 bytes each |

Writing one by hand looks like this.

```ts
import { Effect } from "effect";
import { Address } from "@ethect/core";
import { type AccessList } from "@ethect/core/rpc";

const CONTRACT = Address.makeUnsafe("0x5FbDB2315678afecb367f032d93F642f64180aa3");

const list = Effect.gen(function* () {
  const accessList: AccessList.AccessList = [
    {
      address: CONTRACT,
      storageKeys: [`0x${"00".repeat(32)}`], // slot 0
    },
  ];
  return accessList;
});
```

## Result fields

`AccessList.Result`, what `Eth.createAccessList` returns.

| Field | Type | Notes |
| --- | --- | --- |
| `accessList` | `AccessList.AccessList` | what the transaction touches |
| `gasUsed` | `bigint` | the gas the transaction uses when sent with that list |
| `error` | `string` (optional) | set when the transaction would fail |

## Behavior

- **An address can have no keys.** An entry with an empty `storageKeys` declares the address
  alone.
- **An empty list is a list.** A transfer of ether to an account without code gives `[]`.
- **Storage keys are 32 bytes.** A shorter key is refused by the schema.
- **`error` is not a failure.** A transaction that would revert still gives a result, with
  `error` set. Test it before using the list.
- **Lowercase addresses.** The addresses of a list returned by a node are lowercase.
