> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainstack.com/llms.txt
> Use this file to discover all available pages before exploring further.

# eth_getBlockByNumber | Gnosis

Gnosis Chain API method that returns information about the block matching the given block number. This method can retrieve a wide range of information about the block, such as its hash, timestamp, difficulty, and gas limit. You can also retrieve transaction objects included in the block if needed.

<Check>
  **Get your own node endpoint today**

  [Start for free](https://console.chainstack.com/) and get your app to production levels immediately. No credit card required.

  You can sign up with your GitHub, X, Google, or Microsoft account.
</Check>

## Parameters

* `quantity or tag` — the integer of a block encoded as hexadecimal or the string with:

  * `latest` — the most recent block in the blockchain and the current state of the blockchain at the most recent block. A chain reorganization is to be expected.
  * `safe` — the block that received justification from the beacon chain. Although this block could be involved in a chain reorganization, it would necessitate either a coordinated attack by the majority of validators or an instance of severe propagation latency.
  * `finalized` — the block accepted as canonical by more than 2/3 of the validators. A chain reorganization is extremely unlikely, and it would require at least 1/3 of the staked ETH to be burned.
  * `earliest` — the earliest available or genesis block
  * `pending` — the pending state and transactions block. The current state of transactions that have been broadcast to the network but have not yet been included in a block.

<Note>
  See the [default block parameter](https://eth.wiki/json-rpc/API#the-default-block-parameter).
</Note>

* `boolean` — if `true`, it returns the detail of each transaction. If `false`, only the hashes of the transactions.

## Response

* `object` — a block object, or `null` when no block was found.
  * `number` — the block number of the requested block, encoded as hexadecimal. `null` if the block is pending.
  * `hash` — the block hash of the requested block. `null` if the block pending.
  * `parenthash` — hash of the previous block used to generate the current block. Also known as the 'parent block'.
  * `nonce` — the hash used to demonstrate proof-of-work. `null` if the block pending. It returns `0x0000000000000000` when the consensus is proof-of-stake.
  * `sha3uncles` — the hash of the list of uncles included in the block. It is used to identify the block uniquely and to verify the integrity of the block's data.
  * `logsbloom` — the bloom filter for the logs of the block, a data structure that allows for efficient membership testing of elements in a set, in this case, the logs included in the block. `null` if pending.
  * `transactionsroot` — the root of the transaction trie of the block. The `transactionsRoot` field allows Gnosis Chain nodes to verify the integrity of the transactions in a block.
  * `stateroot` — the root of the final state trie of the block. The `stateroot` field is included in the block header and is used to verify the integrity of the state at the time the block was processed
  * `receiptsroot` — the root of the receipts trie of the block. A 32-byte hash of the root node of the receipts trie of all transactions in the block. It is used to verify the integrity of the receipts data for all transactions in the block.
  * `miner` — the address of the miner receiving the reward.
  * `difficulty` — a measure of how hard it is to find a valid block for the Gnosis blockchain. It is a number that increases as more miners join the network and more blocks are added to the chain. Encoded as hexadecimal.
  * `totaldifficulty` — `null`. This field is obsolete as it was used during Ethereum's Proof of Work (PoW) era. Gnosis Chain uses POSDAO (Proof of Stake-based Delegated Proof of Authority) consensus and this value is not relevant.
  * `extradata` — extra data included in a block by the miner who mined it. It often includes messages or other information related to the block.
  * `size` — the size of this block in bytes as an integer value, encoded as hexadecimal.
  * `gaslimit` — the maximum gas allowed in this block, encoded as hexadecimal.
  * `gasused` — the total used gas by all transactions in this block, encoded as hexadecimal.
  * `timestamp` — the Unix timestamp for when the block was collated.
  * `transactions` — the array of transaction objects. See [eth\_getTransactionByHash](/reference/gnosis-gettransactionbyhash) for the exact shape.
  * `uncles` — the array of uncle hashes.

## `eth_getBlockByNumber` code examples

<CodeGroup>
  ```javascript web3.js theme={"system"}
  const Web3 = require("web3");
  const NODE_URL = "CHAINSTACK_NODE_URL";
  const web3 = new Web3(NODE_URL);

  async function getBlock(blockNumber) {
      const block = await web3.eth.getBlock(blockNumber, false);
      console.log(block);
    }
    
  getBlock("latest")
  ```

  ```javascript ethers.js theme={"system"}
  const ethers = require('ethers');
  const NODE_URL = "CHAINSTACK_NODE_URL";
  const provider = new ethers.JsonRpcProvider(NODE_URL);

  const eth_getBlockByNumber = async () => {
      const blockByNumber = await provider.send("eth_getBlockByNumber", ["latest",false]);
       console.log(blockByNumber);
     };

  eth_getBlockByNumber();
  ```

  ```python web3.py theme={"system"}
  from web3 import Web3
  node_url = "CHAINSTACK_NODE_URL"
  web3 = Web3(Web3.HTTPProvider(node_url))

  print(web3.eth.get_block("latest", False))
  ```
</CodeGroup>

## Use case

The `eth_getBlockByNumber` method can determine whether a block you are analyzing has been included in the main chain or was forked due to a "reorg".

A block hash is generated through a cryptographic hash function, which takes the block's data, including transactions and other information, and the hash of the parent block (the previous block) and outputs a unique, fixed-length digest. This hash represents the current block within the blockchain.

The script compares the parent hash of the following block with the hash under inspection. If the two values match, it can be concluded that the block was included in the main chain. Conversely, if the values do not match, it indicates that the block was not used to generate the next block's hash and has therefore been excluded from the main chain, resulting in a forked block.

```javascript index.js theme={"system"}
const Web3 = require("web3");

const NODE_URL = "YOUR_CHAINSTACK_ENDPOINT"
const web3 = new Web3(NODE_URL)

// If the hash of the block to inspect is === to the parent hash of the next block, then this is not a forked block.
async function isForked(block) {

    const nextBlock = blockToInspect + 1
    console.log(`Block to inspect: ${block}`)
    console.log(`Next block: ${nextBlock} \n`)
    
    const blockToInspectHash = (await web3.eth.getBlock(block, false)).hash
    console.log(`Block hash of the block you are inspecting: ${blockToInspectHash} \n`)

    const nextBlockParentHash = (await web3.eth.getBlock(nextBlock, false)).parentHash
    console.log(`Parent hash of the next block: ${nextBlockParentHash} \n`)

    if (String(nextBlockParentHash) == String(nextBlockParentHash)) {
        console.log(`You are inspecting the correct block`)
        return false

    } else {
        console.log(`You are inspecting a forked block!`)
        return true
    }
}

const blockToInspect = 16394103
isForked(blockToInspect)
```

In this case, the `eth_getBlockByNumber` is used to retrieve the hash of a block you want to analyze and the parent hash of the next block.


## OpenAPI

````yaml /openapi/gnosis_node_api/blocks_info/eth_getBlockByNumber.json POST /512e720763b369ed620657f84d38d2af
openapi: 3.0.0
info:
  title: Upload
  version: 1.0.0
  description: This is an API for interacting with a Chainstack node.
servers:
  - url: https://nd-500-249-268.p2pify.com
security: []
paths:
  /512e720763b369ed620657f84d38d2af:
    post:
      tags:
        - upload
      summary: eth_getBlockByNumber
      operationId: getBlockByNumber
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                id:
                  type: integer
                  default: 1
                jsonrpc:
                  type: string
                  default: '2.0'
                method:
                  type: string
                  default: eth_getBlockByNumber
                params:
                  type: array
                  items:
                    anyOf:
                      - type: string
                        title: Block identifier
                        description: The block number or tag.
                      - type: boolean
                        title: Transaction selector
                        description: >-
                          True for the full transactions, false for only the
                          transaction hashes.
                  default:
                    - latest
                    - false
      responses:
        '200':
          description: The block information
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                  id:
                    type: integer
                  result:
                    type: object

````