安装hardhat环境(windows vscode)

2024-01-15  本文已影响0人  cc卡耐基
yarn init 
question name:
question version:
question descrciption:
......
yarn add --dev hardhat
yarn hardhat

这里会有几个选项,我选的是一个创建一个简单的project,如果是typescript,就好像只有一个选项。另外几个选项一路回车就好。

还有几个dependency,也安装一下,我自己安装的时候好像报错了。然后根据错误提示又重新安装了一下。(建议用梯子)

{
  "name": "hardhat-test",
  "version": "1.0.0",
  "license": "MIT",
  "devDependencies": {
    "@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
    "@nomicfoundation/hardhat-ethers": "^3.0.0",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.0",
    "@nomicfoundation/hardhat-toolbox": "^4.0.0",
    "@nomicfoundation/hardhat-verify": "^2.0.0",
    "@typechain/ethers-v6": "^0.5.0",
    "@typechain/hardhat": "^9.0.0",
    "@types/chai": "^4.2.0",
    "@types/mocha": "^10.0.6",
    "chai": "^4.2.0",
    "hardhat": "^2.19.4",
    "hardhat-gas-reporter": "^1.0.8",
    "solidity-coverage": "^0.8.1",
    "ts-node": "^10.9.2",
    "typechain": "^8.3.0",
    "typescript": "^5.3.3"
  }
}
yarn hardhat compile

这个操作的确比用node自己构建省心了,框架还是有很多方便的地方的。

yarn hardhat run .\scripts\xxxxx.js //这个就是你自己的部署脚本

这里可能会报一些错误

TypeError: (0 , ethers_1.getAddress) is not a function
    at new HardhatEthersSigner.....
......

可以参考这里,可以注意一下答案中的评论。
解决方案是执行这个命令,就是再安装一个hardhat-ethers插件

yarn add --dev hardhat @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers
上一篇下一篇

猜你喜欢

热点阅读