# Block

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

## Examples

### Converting from RPC Format

Blocks can be converted from RPC format to internal format using [`Block.fromRpc`](/api/Block/fromRpc):

```ts twoslash
import 'ox/window'
import { Block } from 'ox'

const block = await window
  .ethereum!.request({
    method: 'eth_getBlockByNumber',
    params: ['latest', false]
  })
  .then(Block.fromRpc) // [!code hl]
// @log: {
// @log:   // ...
// @log:   hash: '0xebc3644804e4040c0a74c5a5bbbc6b46a71a5d4010fe0c92ebb2fdf4a43ea5dd',
// @log:   number: 19868020n,
// @log:   size: 520n,
// @log:   timestamp: 1662222222n,
// @log:   // ...
// @log: }
```

## Functions

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

## Types

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Block.Block`](/api/Block/types#blockblock) | A Block as defined in the [Execution API specification](https://github.com/ethereum/execution-apis/blob/main/src/schemas/block.yaml). |
| [`Block.Hash`](/api/Block/types#blockhash) | A Block hash. |
| [`Block.Identifier`](/api/Block/types#blockidentifier) | A Block identifier. |
| [`Block.Number`](/api/Block/types#blocknumber) | A Block number. |
| [`Block.Rpc`](/api/Block/types#blockrpc) | An RPC Block as defined in the [Execution API specification](https://github.com/ethereum/execution-apis/blob/main/src/schemas/block.yaml). |
| [`Block.Tag`](/api/Block/types#blocktag) | A Block Tag as defined in the [Execution API specification](https://github.com/ethereum/execution-apis/blob/main/src/schemas/block.yaml). |
