> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Block.fromRpc

:::info
`Block.fromRpc` is a re-export of ox's [`Block.fromRpc`](https://oxlib.sh/api/Block/fromRpc). Refer to the ox documentation for the full reference.
:::

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

## Imports

```ts
import { Block } from 'viem/utils'
```

## Examples

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

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`](/docs/utilities/block/types#block).

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

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

## Parameters

### block

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

The RPC block to convert.

## Return Type

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

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