Search code examples
solidityethers.jshardhat

Solidity, compiler version error incompatible


I know is a typical error but I don't know how to solve it. I have tried to add the compile version in the hardhat config file but it doesn't work.

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

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

  • contracts/MarketOrder.sol (^0.8.8) imports @openzeppelin/contracts/token/ERC20/ERC20.sol (^0.7.0)

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

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

Without adding the 0.7.0:

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

The Solidity version pragma statement in these files doesn't match any of the configured compilers in your config. Change the pragma or configure additional compiler versions in your hardhat config.

  * @openzeppelin/contracts/token/ERC20/ERC20.sol (^0.7.0)
  * @openzeppelin/contracts/math/SafeMath.sol (^0.7.0)
  * @openzeppelin/contracts/token/ERC20/IERC20.sol (^0.7.0)

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

  * contracts/MarketOrder.sol (^0.8.8) imports @openzeppelin/contracts/token/ERC20/ERC20.sol (^0.7.0)

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.

  * @uniswap/v3-periphery/contracts/libraries/TransferHelper.sol

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

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

Solution

  • Inside the hardhat.config file you can add multiple compiler versions, find the snippet similar to and add the compiler version which is required.

    solidity: {
       compilers: [
         {
            version: "0.8.8",
          },
          {
             version: "0.7.0",
          },
         ],
     }