介绍
- 编译、部署、测试和调试以太坊应⽤的开发环境,围绕 task(任务)和plugins(插件)概念设计
- 在命令⾏运⾏Hardhat时,都是在运⾏任务,例如:
npx hardhat compile正在运⾏compile任务
- Hardhat node:开发区块链,提供本地模拟的链上环境
- ⽂档
使用步骤
- 创建工程
- 安装:
npm install —save hardhat
- 在⽬录下执⾏
npx hardhat 创建项⽬
- 查看所有任务:
npx hardhat
- 合约编译
- 配置网络
- 在
hardhat.config文件下进行networks参数配置
- 部署脚本
- 启动Hardhat Node⽹络
- 执⾏部署
- 执行
npx hardhat run scripts/deploy.js --network localhost
- 测试
hardhat实战
- 列出所有可以执行的hardhat任务
- 调试利器
- 进入命令行调试
npx hardhat console --network localhost
- fork主网/测试网进行调试
npx hardhat node --fork https://rinkeby.infura.io/v3/<key>
- 灵活参数部署,利用hardhat可以在代码中引用
- 设置
HARDHAT_NETWORK环境变量
- 使用node部署
- 代码扁平 (用于合约验证)
npx hardhat flatten xxx.sol
- 代码验证
require("@nomiclabs/hardhat-etherscan");
npx hardhat verify address --network xxx
- ABI导出
require('hardhat-abi-exporter')
yarn run hardhat export-abi