yarn add hardhat --dev yarn hardhat // 选择empty hardhat.config.js
yarn add --dev @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers @nomiclabs/hardhat-etherscan @nomiclabs/hardhat-waffle chai ethereum-waffle hardhat hardhat-contract-sizer hardhat-deploy hardhat-gas-reporter prettier prettier-plugin-solidity solhint solidity-coverage dotenv
编写的tasks可以很方便的在终端中进行调用
const { task } = require("hardhat/config"); task("block-number", "Prints the current block number.").setAction( async (taskArgs, hre) => { const blockNumber = await hre.ethers.provider.getBlockNumber(); console.log(`Current block Number is ${blockNumber}`); } );
以上task实现了查看block-number
,第一个参数为task的名称,第二个参数为描述,setAction
用来描述真正这个task要实现的功能。
链接地址:https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-etherscan
This plugin helps you verify the source code for your Solidity contracts on Etherscan
npm install --save-dev @nomiclabs/hardhat-etherscan
require("@nomiclabs/hardhat-etherscan"); const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY etherscan: { apiKey: ETHERSCAN_API_KEY, },