10.区块链系列之hardhat部署抵押赎回Fund合约
本文继续通过笔者学习到的抵押赎回智能合约Fund来进一步学习solidity语言,加深对开发的理解,其中通过storage节省gas是需要重点实践的,毕竟涉及到资产
代码已提交至https://gitee.com/SJshenjian/blockchain/tree/master/hardhat-fund-me-fcc
1. 依赖安装
https://gitee.com/SJshenjian/blockchain.git
cd hardhat-fund-me-fcc
yarn
若出现如下错误
fatal: unable to access 'https://github.com/ethereumjs/ethereumjs-abi.git/': OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
在yarn.lock中ethereumjs-abi指定具体版本再次执行yarn即可
修改前
eth-sig-util@^1.4.2:
version "1.4.2"
resolved "https://registry.yarnpkg.com/eth-sig-util/-/eth-sig-util-1.4.2.tgz#8d958202c7edbaae839707fba6f09ff327606210"
integrity sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=
dependencies:
ethereumjs-abi "git+https://github.com/ethereumjs/ethereumjs-abi.git"
ethereumjs-util "^5.1.1"
修改后
eth-sig-util@^1.4.2:
version "1.4.2"
resolved "https://registry.yarnpkg.com/eth-sig-util/-/eth-sig-util-1.4.2.tgz#8d958202c7edbaae839707fba6f09ff327606210"
integrity sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=
dependencies:
ethereumjs-abi "0.6.8"
ethereumjs-util "^5.1.1"
2. 将.env环境中配置修改为自己的配置
PRIVATE_KEY=
GOERLI_RPC_URL=
ETHERSCAN_API_KEY=
COINMARKETCAP_API_KEY=
3. 部署合约
执行yarn hardhat deploy
部署合约可看到本地部署成功
4. 代码特别注意事项
- 文件deploy/00-deploy-mocks.js只有是本地网络才会进行部署
- 文件deploy/99-deploy-storage-fun.js示例了storage部署,img中有具体变量存储细节
- FundMe.sol中有cheaperWithdraw与Withdraw两个函数,注意其区别
- test部分较之前比较全面,建议执行遍测试加深理解
- 其他细节自行学习研究,如有更多注意事项欢迎留言