【问题标题】:Failing to compile multiple Solidity versions无法编译多个 Solidity 版本
【发布时间】:2021-09-10 18:08:55
【问题描述】:

我正在尝试编译(通过 Hardhat)一个合同,该合同导入了多个具有不同 Solidity 版本的接口,但我收到以下错误:

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

These files and its dependencies cannot be compiled with your config. This can happen because they have incompatible Solidity pragmas, or don't match any of your configured Solidity compilers.

  * contracts/FlashLoaner.sol

Flashloaner.sol:

pragma solidity >=0.5.0 <=0.8.0;

import '@uniswap/v2-periphery/contracts/interfaces/IWETH.sol';
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import '@aave/protocol-v2/contracts/interfaces/ILendingPool.sol'; //---> Issue
import "hardhat/console.sol";


contract FlashLoaner {
    struct MyCustomData {
        address token;
        uint256 repayAmount;
    }

    address public logicContract;
    
    function execute(address _weth, address _contract) external view {
        console.log(_weth);
    }
}

问题在于@aave/protocol-v2/contracts/interfaces/ILendingPool.sol。如果我将其注释掉,我的合同就会编译得很好。

IlendingPool.sol:pragma solidity 0.6.12;

IERC20.sol:pragma solidity ^0.5.0;

IWETH.sol:pragma solidity &gt;=0.5.0;

Hardhat.config:

module.exports = {
  solidity: {
    compilers: [
      {
        version: "0.5.7"
      },
      {
        version: "0.8.0"
      },
      {
        version: "0.6.12"
      }
    ]
  }
   ...

【问题讨论】:

    标签: compiler-errors ethereum solidity hardhat


    【解决方案1】:

    解决方案:

    从每个界面中获取我感兴趣的功能的签名,并将它们放在我自己的界面上pragma solidity ^0.8.0

    【讨论】:

    • 是的,这行得通,可惜编译器让我们跳过这些荒谬的圈子,因为它认为函数可能不存在于特定地址
    【解决方案2】:

    只需尝试在 hardhat.config.js 上进行设置

        module.exports = {   solidity: {
            compilers: [
              {
                version: "0.5.5",
              },
              {
                version: "0.6.7",
                settings: {},
              },
            ],   
    }, 
    
    };
    

    see more!!!!

    【讨论】:

    • 嗨!这与我在最初的帖子中尝试的有什么不同? (最后一部分)
    【解决方案3】:

    我也遇到过类似的问题。

    在我的例子中,我的合约使用了 pragma solidity 版本 ^0.8.0

    为了解决这个问题,我将这些行添加到了我的 hardhat.config.js(大多数情况下在现有的 module.exports 中)。

    module.exports = {
      solidity: "0.8.0",
    }
    

    我只是删除了版本之前的“^”。 我希望它可以帮助某人。

    【讨论】:

      猜你喜欢
      • 2022-11-12
      • 1970-01-01
      • 2021-08-02
      • 2019-06-09
      • 2022-07-12
      • 2021-07-25
      • 2018-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多