Skip to content

Block

Utilities & types for working with Blocks as defined in the Execution API specification

Examples

Converting from RPC Format

Blocks can be converted from RPC format to internal format using Block.fromRpc:

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

Functions

NameDescription
Block.fromRpcConverts a Block.Rpc to an Block.Block.
Block.toRpcConverts a Block.Block to an Block.Rpc.

Types

NameDescription
Block.BlockA Block as defined in the Execution API specification.
Block.HashA Block hash.
Block.IdentifierA Block identifier.
Block.NumberA Block number.
Block.RpcAn RPC Block as defined in the Execution API specification.
Block.TagA Block Tag as defined in the Execution API specification.