How to Get the Latest Block Number (Head Block) on Ethereum Blockchain?


The simplest method/function to retrieve the latest block number on ETH aka Ethereum Blockchain is via the following method:

1
2
3
4
5
6
7
const Web3 = require('web3');
 
const getBlockNumber = async() => {
    const MAIN_ENDPOINT = "https://mainnet.infura.io/v3/...";
    const web3 = new Web3(ENDPOINT);
    return await web3.eth.getBlockNumber();
}
const Web3 = require('web3');

const getBlockNumber = async() => {
    const MAIN_ENDPOINT = "https://mainnet.infura.io/v3/...";
    const web3 = new Web3(ENDPOINT);
    return await web3.eth.getBlockNumber();
}

You would need the web3 library:

1
npm install web3
npm install web3

Ethereum Blockchain

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
115 words
Last Post: How to Get the Gas Price and Gas Fee on Ethereum Blockchain?
Next Post: How to Check if a Given String is a Valid Ethereum Wallet Address?

The Permanent URL is: How to Get the Latest Block Number (Head Block) on Ethereum Blockchain?

Leave a Reply