1

I have a contract in which I imports a package which in return imports IERC20.sol from openzeppelin which has ^0.7.0 solidity version and my contract has 0.8.10 solidity version. I have mentioned both the solidity versions in hardhat.config.js file but still it's throwing me this error:

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

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

  * contracts/Test.sol (0.8.10) depends on @openzeppelin/contracts/token/ERC20/IERC20.sol (^0.7.0)

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

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

I have the hardhat.config.js file like this:

require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: {
    compilers: [
      {
        version: "0.8.10",
      },
      {
        version: "0.6.12",
      },
      {
        version:"0.7.0",
      }
    ],
  },
};

I have mentioned all the solidity versions I need for my contract but still hardhat throwing me the error on compiling the smart contract. Does anyone know what I am doing wrong here?

1 Answer 1

2

There is a very similar topic here: https://stackoverflow.com/questions/68163319/failing-to-compile-multiple-solidity-versions

Someone mentioned this Hardhat FAQ that says:

But in some scenarios, you might have a contract with pragma version ^0.7.0 that imports a contract with ^0.6.0. This can never be compiled. Pragma versions indicate which subset of the compiler versions can be used, and if two pragma versions don’t intersect (like in this example), then the files cannot be compiled. Period.

2
  • ohk. I thought we can import lower version pragma into higher version pragma contract and will compile. Thanks Commented Oct 8, 2022 at 12:35
  • @RishabhRaghwendra you welcome, if it’s enough pls mark as accepted :)
    – matank001
    Commented Oct 8, 2022 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.