# Log

An event log as a node returns it: the contract that emitted it, its topics and data, and its
place in the chain.

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

const TOKEN = Address.makeUnsafe("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2");

const emitters = Effect.gen(function* () {
  const logs = yield* Eth.getLogs({ address: TOKEN, fromBlock: "finalized" });
  // logs: ReadonlyArray<Log.Log>
  return logs.map((log) => [log.blockNumber, log.transactionHash, log.topics[0]]);
});
```

## Schemas

| Schema | Type | Describes | Returned by |
| --- | --- | --- | --- |
| `Log.schema` | `Log.Log` | one log | [`Eth.getLogs`](https://ethect.dev/rpc/eth/get-logs/), [`Eth.getFilterChanges`](https://ethect.dev/rpc/eth/filters/#getfilterchanges), [`Eth.getFilterLogs`](https://ethect.dev/rpc/eth/filters/#getfilterlogs), [`Eth.subscribe.logs`](https://ethect.dev/rpc/eth/subscribe/logs/) |

A log is also what the `logs` of a [`Receipt`](https://ethect.dev/rpc/types/receipt/) hold, and the `logs`
of a simulated call in [`Simulate`](https://ethect.dev/rpc/types/simulate/).

Import the type to name it in your own signatures.

```ts
import type { Log } from "@ethect/core/rpc";

const isMined = (log: Log.Log): boolean => log.blockNumber !== null;
```

## Fields

| Field | Type | Notes |
| --- | --- | --- |
| `address` | `Address` | the contract that emitted the log |
| `topics` | `ReadonlyArray<Hash>` | up to four: usually the hash of the event signature, then the indexed arguments |
| `data` | `Hex` | the arguments that are not indexed, ABI-encoded |
| `blockHash` | `Hash \| null` | `null` on a pending log |
| `blockNumber` | `bigint \| null` | `null` on a pending log |
| `blockTimestamp` | `bigint` (optional) | seconds since the Unix epoch, where the node sends it |
| `transactionHash` | `Hash \| null` | `null` on a pending log |
| `transactionIndex` | `number \| null` | the position of the transaction in its block |
| `logIndex` | `number \| null` | the position of the log in its block |
| `removed` | `boolean` (optional) | `true` when a reorg dropped the block the log was in |

## Behavior

- **Hex in, hex out.** A log is as the node sent it: `topics` and `data` are hex.
  [`Ev.decode`](https://ethect.dev/reference/ev/decode/) reads them as the events of a contract.
- **`null` means pending.** The five position fields are `null` only while the transaction of
  the log is not mined. They are always present, so they are typed `| null`, not optional.
- **`removed` comes with a reorg.** A [log subscription](https://ethect.dev/rpc/eth/subscribe/logs/) pushes
  the logs of a dropped block a second time with `removed: true`. Elsewhere anvil sends
  `false`.
- **Optional means absent.** `blockTimestamp` and `removed` are left out of the object when the
  node does not send them. anvil sends both.
- **Lowercase address.** `address` is lowercase:
  [`Address.checksum`](https://ethect.dev/reference/primitives/address/) gives the EIP-55 form.
