eth_getBlockByNumber

Ethereum RPC

Overview

The eth_getBlockByNumber is an Ethereum JSON-RPC method that allows developers to query a specific block in the Ethereum 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

Returns

The response from the eth_getBlockByNumber method is a JSON object containing the following fields:

NameDescription
numberThe block number (hexadecimal string).
hashThe block hash (32-byte string).
parentHashThe hash of the parent block (32-byte string).
nonceThe nonce used to generate the block (8-byte string).
sha3UnclesThe SHA3 hash of the uncles in the block (32-byte string).
logsBloomThe logs bloom filter of the block (256-byte string).
transactionsRootThe root of the transaction trie (32-byte string).
stateRootThe root of the state trie (32-byte string).
minerThe address of the miner who mined the block (20-byte string).
difficultyThe difficulty of the block (hexadecimal string).
totalDifficultyThe total difficulty of the chain up to this block (hexadecimal string).
extraDataExtra data included by the miner in the block (byte string).
sizeThe block size in bytes (hexadecimal string).
gasLimitThe gas limit for the block (hexadecimal string).
gasUsedThe total gas used by all transactions in the block (hexadecimal string).
timestampThe block timestamp (hexadecimal string).
transactionsAn array of transaction objects or transaction hashes, depending on the returnFullTransactionObjects parameter.
unclesAn array of uncle block hashes (32-byte strings).

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

NameDescription
hashThe block hash (32-byte string).
nonceThe nonce used to generate the block (8-byte string).
blockHashThe block hash where the transaction is included (32-byte string).
blockNumberThe block number where the transaction is included (hexadecimal string).
transactionIndexThe index of the transaction in the block (hexadecimal string).
fromThe sender address (20-byte string).
toThe recipient address, or null for contract creation transactions (20-byte string).
valueThe value being transferred (hexadecimal string).
gasPriceThe gas price in wei (hexadecimal string).
gasThe gas provided for the transaction (hexadecimal string)..
inputThe input data for the transaction (byte string).

Request

curl --location 'https://api.tatum.io/v3/blockchain/node/ethereum-mainnet/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_getBlockByNumber",
  "params": ["latest", true]
}'
// yarn add @tatumio/tatum

import { TatumSDK, Ethereum, Network } from '@tatumio/tatum'

const tatum = await TatumSDK.init<Ethereum>({ network: Network.ETHEREUM })

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

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