# Block.fromRpc

Converts a [`Block.Rpc`](/api/Block/types#rpc) to an [`Block.Block`](/api/Block/types#block).

## Imports

:::code-group
```ts [Named]
import { Block } from 'ox'
```

```ts [Entrypoint]
import * as Block from 'ox/Block'
```
:::

## Examples

```ts twoslash
// @noErrors
import { Block } from 'ox'

const block = Block.fromRpc({
  // ...
  hash: '0xebc3644804e4040c0a74c5a5bbbc6b46a71a5d4010fe0c92ebb2fdf4a43ea5dd',
  number: '0xec6fc6',
  size: '0x208',
  timestamp: '0x63198f6f'
  // ...
})
// @log: {
// @log:   // ...
// @log:   hash: '0xebc3644804e4040c0a74c5a5bbbc6b46a71a5d4010fe0c92ebb2fdf4a43ea5dd',
// @log:   number: 19868020n,
// @log:   size: 520n,
// @log:   timestamp: 1662222222n,
// @log:   // ...
// @log: }
```

### End-to-end

Below is an end-to-end example of using `Block.fromRpc` to fetch a block from the network and convert it to an [`Block.Block`](/api/Block/types#block).

```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: }
```

:::note
For simplicity, the above example uses `window.ethereum.request`, but you can use any type of JSON-RPC interface.
:::

## Definition

```ts
function fromRpc<block, includeTransactions, blockTag>(
  block: block | Rpc | null,
  _options?: fromRpc.Options<includeTransactions, blockTag>,
): block extends Rpc ? Block<includeTransactions, blockTag> : null
```

**Source:** [src/core/Block.ts](https://github.com/wevm/ox/blob/main/src/core/Block.ts#L318)

## Parameters

### block

* **Type:** `block | Rpc | null`

The RPC block to convert.

## Return Type

An instantiated [`Block.Block`](/api/Block/types#block).

`block extends Rpc ? Block<includeTransactions, blockTag> : null`
