全部教程·
区块链·
Web3.js
[目录]
·
web3.js 查询最新区块号
web3.js 教程
web3.js 环境搭建
web3.js 访问区块链网络
web3.js 智能合约对象
web3.js 调用函数
web3.js 交易操作
安装 ethereumjs-tx
web3.js 准备账号
web3.js 执行交易
web3.js 交易小结
web3.js 部署智能合约
web3.js 准备智能合约
web3.js 执行部署
web3.js 调用写函数
web3.js 执行写函数调用
web3.js 智能合约事件
web3.js 执行事件查询
web3.js 查询最新区块号
web3.js 查询最新区块
web3.js 查询指定区块
web3.js 查询区块交易
web3.js 查询 gas 价格
web3.js sha3
web3.js underscore 库
web3.js 教程
web3.js 环境搭建
web3.js 访问区块链网络
web3.js 智能合约对象
web3.js 调用函数
web3.js 交易操作
安装 ethereumjs-tx
web3.js 准备账号
web3.js 执行交易
web3.js 交易小结
web3.js 部署智能合约
web3.js 准备智能合约
web3.js 执行部署
web3.js 调用写函数
web3.js 执行写函数调用
web3.js 智能合约事件
web3.js 执行事件查询
web3.js 查询最新区块号
web3.js 查询最新区块
web3.js 查询指定区块
web3.js 查询区块交易
web3.js 查询 gas 价格
web3.js sha3
web3.js underscore 库
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
下一章:web3.js 查询最新区块
要查询最新区块,可以使用web3.eth.getBlock('latest')函数。代码如下:app.jsconst Web3 = require('web3')const web3 = new Web3('h ...