参考:https://learnblockchain.cn/docs/hardhat/tutorial/creating-a-new-hardhat-project.html
mkdir hardhat-tutorial(这个名称随意)
cd hardhat-tutorial
npm init --yes
npm install --save-dev hardhat
2、目录下运行
npx hardhat
3、选择 Create an empty hardhat.config.js 回车
写合约 或者 从其他地方复制合约过来
4、install 相关合约依赖
如:npm install @confluxfans/contracts
5、先做 flatten 再编译部署,如将 MonkeyFactory 合约代码平铺在一个文件
npx hardhat flatten contracts/MonkeyFactory.sol > contracts/MonkeyFactoryMerged.sol
6、编译
npx hardhat compile 或者 使用conflux studio直接编译&部署
编译失败则
1、关注下 hardhat.config.js 中 solidty 版本,不对修改
2、flatten 后的文件中搜素一下这个括号中的内容 (// SPDX-License-Identifier: MIT) ,只能留文件最顶部那一个,其他全部删除
7、部署后即可在 confluxscan 上验证了,验证的时候选择 solidty 版本 以及 许可协议(选 MIT License 即可)
本文详细介绍了如何使用Hardhat创建并部署智能合约的过程。包括初始化项目、安装依赖、编写及编译合约、以及如何在Confluxscan上验证已部署的合约。
1192

被折叠的 条评论
为什么被折叠?



