Web3js教程

web3.js 查询最新区块号

要查询最新区块号,可以使用 web3.eth.getBlockNumber()函数。
代码如下:
app.js
const Web3 = require('web3')
const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY') // YOUR_INFURA_API_KEY替换为你自己的key
// 查询最新区块
web3.eth.getBlockNumber().then(console.log)
运行app.js:
$ node app
输出
8718170
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4