# Log

Utilities & types for working with Logs as defined in the [Execution API specification](https://github.com/ethereum/execution-apis/blob/main/src/schemas/receipt.yaml)

:::tip
Utilities for Log encoding & decoding can be found on the [`AbiEvent`](/api/) module.
:::

## Examples

### Converting from RPC Format

Logs can be converted from their RPC format using [`Log.fromRpc`](/api/Log/fromRpc):

```ts twoslash
import 'ox/window'
import { AbiEvent, Hex, Log } from 'ox'

const transfer = AbiEvent.from(
  'event Transfer(address indexed from, address indexed to, uint256 indexed value)'
)

const { topics } = AbiEvent.encode(transfer)

const logs = await window.ethereum!.request({
  method: 'eth_getLogs',
  params: [
    {
      address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
      fromBlock: Hex.fromNumber(19760235n),
      toBlock: Hex.fromNumber(19760240n),
      topics
    }
  ]
})

const log = Log.fromRpc(logs[0]) // [!code focus]
// @log: {
// @log:   address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
// @log:   blockHash: '0xabe69134e80a12f6a93d0aa18215b5b86c2fb338bae911790ca374a8716e01a4',
// @log:   blockNumber: 19760236n,
// @log:   data: '0x',
// @log:   logIndex: 271,
// @log:   removed: false,
// @log:   topics: [
// @log:     "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
// @log:     "0x0000000000000000000000000000000000000000000000000000000000000000",
// @log:     "0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1",
// @log:     "0x000000000000000000000000000000000000000000000000000000000000025b",
// @log:   transactionHash:
// @log:     '0xcfa52db0bc2cb5bdcb2c5bd8816df7a2f018a0e3964ab1ef4d794cf327966e93',
// @log:   transactionIndex: 145,
// @log: }
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Log.fromRpc`](/api/Log/fromRpc) | Converts a [`Log.Rpc`](/api/Log/types#rpc) to an [`Log.Log`](/api/Log/types#log). |
| [`Log.toRpc`](/api/Log/toRpc) | Converts a [`Log.Log`](/api/Log/types#log) to a [`Log.Rpc`](/api/Log/types#rpc). |

## Types

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Log.Log`](/api/Log/types#loglog) | A Log as defined in the [Execution API specification](https://github.com/ethereum/execution-apis/blob/main/src/schemas/receipt.yaml). |
| [`Log.Rpc`](/api/Log/types#logrpc) | An RPC Log as defined in the [Execution API specification](https://github.com/ethereum/execution-apis/blob/main/src/schemas/receipt.yaml). |
