Skip to content

getBlock

Returns information about a block at an epoch tag/number, block number, or hash.

example.ts
import { publicClient } from "./client";

const block = await publicClient.getBlock();
 
Output: {
hash: "0xd2f1997676690a5d7eb2067846c1c28e6fe47064239b327a2dfcdd8321274b8f",
parentHash: "0x15cbfa0e66693302ddb28015dd3fbac6593a4695c8d6572d2db5964c1ccd4ff2",
height: 100866417n,
deferredStateRoot: "0xae5c788dbe5d4f30fc0f797cb94d9b7635c41e8074082b95735e2b68c77442c7",
...
}

Returns

Block

The block information.

Parameters

blockHash (optional)

  • Type: Hash

Get information about a block by hash.

const block = await publicClient.getBlock({
  blockHash:
    "0xf6cec5af1ee95f56038fc30589bcfeb4b960075c3c76b8a0eaa6d36e8e623b50", 
});

epochTag (optional) defaut

  • Type: latest_mined |latest_state | latest_confirmed | latest_checkpoint | earliest
  • Defaut latest_state

Get information about a block by epoch tag.

const block = await publicClient.getBlock({
  epochTag: "latest_state", 
});

epochNumber (optional)

  • Type: bigint

Get information about a block by epoch number.

const block = await publicClient.getBlock({
  epochNumber: 1n, 
});

blockNumber (optional)

  • Type: bigint

Get information about a block by block number.

const block = await publicClient.getBlock({
  blockNumber: 1n, 
});

includeTransactions (optional)

  • Type: boolean

Whether to include transactions (as a structured array of Transaction objects).

const block = await publicClient.getBlock({
  blockNumber: 1n,
  includeTransactions: true,
});

JSON-RPC Method

cfx_getblockbyhash

cfx_getBlockByEpochNumber

cfx_getBlockByBlockNumber