Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failing to compile multiple Solidity versions

I'm trying to compile (through Hardhat) a contract that imports several interfaces with different Solidity versions but I'm getting the following error:

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);
    }
}

The problem is with @aave/protocol-v2/contracts/interfaces/ILendingPool.sol. If I comment it out, my contract compiles good.

IlendingPool.sol: pragma solidity 0.6.12;

IERC20.sol: pragma solidity ^0.5.0;

IWETH.sol: pragma solidity >=0.5.0;

Hardhat.config:

module.exports = {
  solidity: {
    compilers: [
      {
        version: "0.5.7"
      },
      {
        version: "0.8.0"
      },
      {
        version: "0.6.12"
      }
    ]
  }
   ...
like image 643
dNyrM Avatar asked Dec 17 '25 18:12

dNyrM


2 Answers

Solution:

Grab the signatures from the functions that I'm interested in from each interface, and put them on my own interface with pragma solidity ^0.8.0.

like image 130
dNyrM Avatar answered Dec 20 '25 02:12

dNyrM


I had a similar problem.

In my case, my contracts used pragma solidity version ^0.8.0

To fix the problem, I added those lines to my hardhat.config.js (Inside the existing module.exports for most cases).

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

I just deleted the "^" before the version.

like image 26
Kys3r Avatar answered Dec 20 '25 04:12

Kys3r



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!