无法编译多个 Solidity 版本

dNy*_*yrM 17 compiler-errors ethereum solidity hardhat

我正在尝试编译(通过 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
Run Code Online (Sandbox Code Playgroud)

闪贷者.sol:

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
Run Code Online (Sandbox Code Playgroud)

问题在于@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 >=0.5.0;

安全帽配置:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

dNy*_*yrM 7

解决方案:

从每个接口中获取我感兴趣的函数的签名,并将它们放在我自己的接口上pragma solidity ^0.8.0

  • 是的,这可行,遗憾的是编译器让我们跳过这些荒谬的循环,因为它认为某个函数可能不存在于特定地址 (2认同)

小智 7

我有类似的问题。

就我而言,我的合约使用了 pragma Solidity 版本 ^0.8.0

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

module.exports = {
  solidity: "0.8.0",
}
Run Code Online (Sandbox Code Playgroud)

我只是把版本前的“^”删掉了。


小智 5

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

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

};
Run Code Online (Sandbox Code Playgroud)

查看更多!!!!

  • 你好!这与我在最初的帖子中尝试的有什么不同?(最后一部分) (3认同)