- 官网参考
- 在项目根目录创建
tasks
目录 - 在
tasks
目录下创建block-number.js
文件
const { task } = require("hardhat/config")
task("block-number", "Prints the current", async (taskArgs, hre) => {
const blockNumber = await hre.ethers.provider.getBlockNumber()
console.log(`Current block Number: ${ blockNumber }`)
})
module.exports = {}
require("./tasks/block-number")
- 执行
yarn hardhat
就能查到block-number
命令
AVAILABLE TASKS:
block-number Prints the current
yarn hardhat block-number --network bsctest
> yarn hardhat block-number --network bsctest
yarn run v1.22.19
..\node_modules\.bin\hardhat block-number
Current block Number: 34615136
Done in 2.96s.