eth_getBlockByNumber

How to use it

// yarn add @tatumio/tatum

import { TatumSDK, Base, Network } from "@tatumio/tatum";

const tatum = await TatumSDK.init<Base>({ network: Network.BASE });

const block = await tatum.rpc.getBlockByNumber("latest", true);

await tatum.destroy(); // Destroy Tatum SDK - needed for stopping background jobs

Overview

eth_getBlockByNumber is an method that allows developers to query a specific block in the blockchain by its block number. This method can be used in various scenarios, such as analyzing historical transactions, validating the state of the blockchain, or monitoring the progress of mining activities.

Parameters

There are two required parameters for this method:

  1. blockNumber - The block number of the block to be retrieved. This can be a hexadecimal string or one of the predefined aliases: "earliest", "latest", or "pending".

    Example: "0x1b4"

  2. returnFullTransactionObjects - A boolean value that determines whether the returned block contains complete transaction objects (true) or only transaction hashes (false).

    Example: true

Return Object

The returned block object includes the following fields:

  • number - The block number (hexadecimal string).

  • hash - The block hash (32-byte string).

  • parentHash - The hash of the parent block (32-byte string).

  • nonce - The nonce used to generate the block (8-byte string).

  • sha3Uncles - The SHA3 hash of the uncles in the block (32-byte string).

  • logsBloom - The logs bloom filter of the block (256-byte string).

  • transactionsRoot - The root of the transaction trie (32-byte string).

  • stateRoot - The root of the state trie (32-byte string).

  • miner - The address of the miner who mined the block (20-byte string).

  • difficulty - The difficulty of the block (hexadecimal string).

  • totalDifficulty - The total difficulty of the chain up to this block (hexadecimal string).

  • extraData - Extra data included by the miner in the block (byte string).

  • size - The block size in bytes (hexadecimal string).

  • gasLimit - The gas limit for the block (hexadecimal string).

  • gasUsed - The total gas used by all transactions in the block (hexadecimal string).

  • timestamp - The block timestamp (hexadecimal string).

  • transactions - An array of transaction objects or transaction hashes, depending on the returnFullTransactionObjects parameter.

  • uncles - An array of uncle block hashes (32-byte strings).

If returnFullTransactionObjects is true, the transactions field contains transaction objects with the following fields:

  • hash - The transaction hash (32-byte string).

  • nonce - The number of transactions sent by the sender before this transaction (hexadecimal string).

  • blockHash - The block hash where the transaction is included (32-byte string).

  • blockNumber - The block number where the transaction is included (hexadecimal string).

  • transactionIndex - The index of the transaction in the block (hexadecimal string).

  • from - The sender address (20-byte string).

  • to - The recipient address, or null for contract creation transactions (20-byte string).

  • value - The value being transferred (hexadecimal string).

  • gasPrice - The gas price in wei (hexadecimal string).

  • gas - The gas provided for the transaction (hexadecimal string).

  • input - The input data for the transaction (byte string).

Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "baseFeePerGas": "0x13c",
    "difficulty": "0x0",
    "extraData": "0x",
    "gasLimit": "0x1c9c380",
    "gasUsed": "0x13bb33",
    "hash": "0x1141fda5c9d290557d3d0079f33423e2bc4ccba9b279d23dbc0884687cf36fe5",
    "logsBloom": "0x002b00022008080000800000800000402000000100000189000400200020000000004000020000400000081003041000000100008200200080700000002800080000101800000248008240388000002008100000004808080100000480200800008000401a0000800d0000002000080000001200000004004002001800082201000000408400004000008080000200000400000100200008000000440080000002400000408000049028211020000002041000000120200008000020000001000200000200080600000400204010004080000080040002100000000200002080001008408000000000000000000080406000100000000a400000400000000401",
    "miner": "0x4200000000000000000000000000000000000011",
    "mixHash": "0xf1ae28655be7b11309bb1580f9e2a140c48e601514c78dde5732eecd4bedc59e",
    "nonce": "0x0000000000000000",
    "number": "0xb2e214",
    "parentHash": "0xe12dccfd6bbe81455aaa8449f693558b421981dd8f9217bba1cd12458274cc5d",
    "receiptsRoot": "0x9b6f653ea398a8e8e638c848f409968ce25528ae37b2b2fca7f6ccdc3006a317",