hardhat solidity不同版本,不能正常编译

hardhat.config.js

compilers: [
      {
        version: "0.7.0"
      },
      {
        version: "0.7.3"
      },
      {
        version: "0.8.0"
      },
      {
        version: "0.8.1"
      },
    ]
  },

编译时异常提示

npx hardhat compile
Solidity 0.8.0, 0.8.1 are not fully supported yet. You can still use Hardhat, but some features, like stack traces, might not work correctly.

Learn more at https://hardhat.org/reference/solidity-support"

Error HH606: The project cannot be compiled, see reasons below.

These files import other files that use a different and incompatible version of Solidity:

  • @soliditylabs/erc20-permit/contracts/ERC20Permit.sol (^0.7.0) imports @openzeppelin/contracts/token/ERC20/ERC20.sol (^0.8.0) and @openzeppelin/contracts/utils/Counters.sol (^0.8.0)

These files depend on other files that use a different and incompatible version of Solidity:

  • contracts/ERC20PermitToken.sol (^0.7.0) depends on @openzeppelin/contracts/token/ERC20/ERC20.sol (^0.8.0), @openzeppelin/contracts/utils/Counters.sol (^0.8.0) and 2 other files. Use --verbose to see the full list.

To learn more, run the command again with --verbose

Read about compiler configuration at https://hardhat.org/config

For more info go to https://hardhat.org/HH606 or run Hardhat with --show-stack-traces

请先 登录 后评论

2 个回答

Tiny熊
  擅长:智能合约,以太坊

看提示是你在合约里应用了不兼容的版本,需要修改一下相关合约源代码的版本号。

或者尝试为单个文件设置编译器:

solidity: {
    compilers: [...],
    overrides: {
      "contracts/Foo.sol": {
        version: "0.5.5",
        settings: { }
      }
    }
  }

不过,我自己也没使用过这个方法,可参考文档:https://hardhat.org/guides/compile-contracts.html

请先 登录 后评论
Yee - CTO

hardhat因为深度集成solidity,所以需要支持solidity 0.8的版本,现在的版本看起来是不支持的。

可参考 https://hardhat.org/reference/solidity-support.html

请先 登录 后评论
  • 1 关注
  • 0 收藏,6415 浏览
  • 比特聪 提出于 2021-04-15 09:17