> ## 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.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.chainstack.com/feedback

```json
{
  "path": "/reference/avalanche-getblocknumber",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# eth_blockNumber | Avalanche

Avalanche API method that returns the latest block number of the blockchain. A block number is a hexadecimal number representing the block's position in the blockchain. For example, the block number `0x69B5B` means that the block is the 432,987th block in the blockchain.

<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

* `none`

## Response

* `result` — the integer value of the node's latest block number is synced to encoded as hexadecimal. The block number is used to identify the block's position in the blockchain and is updated every time a new block is added to the chain.

## `eth_blockNumber` 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 getLatestBlockNumber() {
    const block = await web3.eth.getBlockNumber();
    console.log(`Latest block: ${block}`);
  }
    
  getLatestBlockNumber()
  ```

  ```javascript ethers.js theme={"system"}
  const ethers = require('ethers');
  const NODE_URL = "CHAINSTACK_NODE_URL";
  const provider = new ethers.providers.JsonRpcProvider(NODE_URL);

  const eth_getBlockNumber = async () => {
      const block_Number = await provider.getBlockNumber();
      console.log(block_Number);
    };

  eth_getBlockNumber();
  ```

  ```python web3.py theme={"system"}
  from web3 import Web3

  node_url = "CHAINSTACK_NODE_URL"

  web3 = Web3(Web3.HTTPProvider(node_url))
  print (web3.eth.block_number)
  ```
</CodeGroup>

## Use case

A possible use case for the `eth_blockNumber` method in Avalanche is for applications that need to be aware of the current block number—some applications may need to be mindful of the current block number to function correctly. For example, a DApp may use the current block number to determine the expiration date of a time-limited offer.

The following code uses the web3.js library and defines a function called `getCurrentBlockNumber`. When called, this function returns the latest block number from the network, and you can use it in your DApp.

```js web3.js theme={"system"}
const Web3 = require('web3');

// Connect to the Ethereum network
const node_url = "CHAINSTACK_NODE_URL";
const web3 = new Web3(node_url);

// Define a function that returns the current block number
async function getCurrentBlockNumber() {
  const blockNumber = await web3.eth.getBlockNumber();
  return blockNumber;
};

// Use the getCurrentBlockNumber function in your application
async function main() {

  // Let's say you want to offer a special price on a service to a specific user.
  // Offer expires in a week, Avalanche produces 1 block every 2 seconds which means 285600 block per week
  const blockInAWeek = 285600;
  const currentBlockNumber = await getCurrentBlockNumber();
  const offerExpires = currentBlockNumber + blockInAWeek;

  console.log(`Your special offer will expire on block: ${offerExpires}`);
};

main();
```

You can then use your application's `getCurrentBlockNumber` function to get the current block number whenever you need it. In this example, we use it to calculate on which block a special offer to a specific user will expire. We retrieve the block when we issue the offer to the user and add `50400`, which is approximately how many Ethereum blocks are produced weekly. Now, in the `offerExpires` constant, we have the last block when the user can exercise the special price.

Use the `getCurrentBlockNumber` function to compare it to `offerExpires` to know if the offer is still valid.


## OpenAPI

````yaml /openapi/avalanche_node_api/blocks_info/eth_blockNumber.json POST /8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc
openapi: 3.0.0
info:
  title: Chainstack Node API
  version: 1.0.0
  description: This is an API for interacting with a Chainstack node.
servers:
  - url: https://nd-418-459-126.p2pify.com
security: []
paths:
  /8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc:
    post:
      tags:
        - Blocks info
      summary: eth_blockNumber
      operationId: eth_blockNumber
      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_blockNumber
                params:
                  type: array
                  default: []
      responses:
        '200':
          description: The latest block number.
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                  id:
                    type: integer
                  result:
                    type: object

````