1

I have tried everything I know to do (which is limited, ill admit) and I cannot seem to resolve this error.

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.8.0)
  • @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC20/IERC20.sol (^0.8.0)
  • @openzeppelin/contracts/utils/Context.sol (^0.8.0)
  • @openzeppelin/contracts/access/Ownable.sol (^0.8.0)

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

  • contracts/AccessControl.sol (^0.5.0) imports @openzeppelin/contracts/access/Ownable.sol (^0.8.0)
  • contracts/BCToken.sol (^0.5.0) imports @openzeppelin/contracts/token/ERC20/ERC20.sol (^0.8.0)

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

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

For more info go to https://hardhat.org/HH606 or run Hardhat with --show-stack-traces PS C:\Users\smart\WEB3-GAME\Contracts> npx hardhat compile Error HH411: The library @openze import, imported from contracts/BCToken.sol, is not installed. Try installing it using npm.

For more info go to https://hardhat.org/HH411 or run Hardhat with --show-stack-traces PS C:\Users\smart\WEB3-GAME\Contracts> npx hardhat compile Error HH404: File @openzeppelin/contracts/access/ERC20/ERC20.sol, imported from contracts/BCToken.sol, not found.

For more info go to https://hardhat.org/HH404 or run Hardhat with --show-stack-traces PS C:\Users\smart\WEB3-GAME\Contracts> npx hardhat compile 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.

  • contracts/AccessControl.sol (0.8.0)
  • contracts/BCToken.sol (0.8.0)
  • @openzeppelin/contracts/token/ERC20/ERC20.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC20/IERC20.sol (^0.8.0)
  • @openzeppelin/contracts/utils/Context.sol (^0.8.0)
  • @openzeppelin/contracts/access/Ownable.sol (^0.8.0)

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

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

For more info go to https://hardhat.org/HH606 or run Hardhat with --show-stack-traces PS C:\Users\smart\WEB3-GAME\Contracts> npx hardhat compile 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.

  • contracts/AccessControl.sol (^0.8.0)
  • contracts/BCToken.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC20/ERC20.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC20/IERC20.sol (^0.8.0)
  • @openzeppelin/contracts/utils/Context.sol (^0.8.0)
  • @openzeppelin/contracts/access/Ownable.sol (^0.8.0)

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

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

For more info go to https://hardhat.org/HH606 or run Hardhat with --show-stack-traces PS C:\Users\smart\WEB3-GAME\Contracts> npx hardhat compile 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.

  • contracts/AccessControl.sol (^0.8.0)
  • contracts/BCToken.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC20/ERC20.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC20/IERC20.sol (^0.8.0)
  • @openzeppelin/contracts/utils/Context.sol (^0.8.0)
  • @openzeppelin/contracts/access/Ownable.sol (^0.8.0)

AccessControl.Sol

//SPDX-License-Identifier: MIT pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";

contract AccessControl is Ownable {

mapping(address => bool) public admins;

function setAdmin(address user, bool enable) external onlyOwner { admins[user] = enable; }

modifier onlyAdmin() { require( msg.sender == owner() || admins[msg.sender] == true, "AccessControl: Caller doesn't have admin access" ); _; } }

BCToken.sol

//SPDX-License-Identifier: MIT pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "./AccessControl.sol";

contract BCToken is ERC20, AccessControl {

 constructor(uint256 amount) ERC20("BCToken", "BCT") public {}

function mint(address user, uint amount) 
    external 
    onlyAdmin 
    returns(bool)
{
    _mint(user, amount);
    return true;

hardhat.config.js

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

require("dotenv").config();

/** @type import('hardhat/config').HardhatUserConfig */ module.exports = {
solidity: { compilers: [ { version: "0.5.7", }, { version: "0.6.7", settings: {}, }, ],
}, networks: { sepolia: { url: "https://sepolia.infura.io/v3/", accounts: [process.env.KEY], } } }

}

1 Answer 1

0

The contracts you're trying to compile (namely, AccessControl.sol and BCToken.sol) are written for Solidity version "^0.8.0", but those are not the version you specify in hardhat.config.js.

Lets update hardhat.config.js for Solidity version 0.8.0 and it should work.

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
    solidity: {
        compilers: [
            { version: "0.5.7" },
            { version: "0.6.7", settings: {} },
            { version: "0.8.0", settings: {} }, // Add this line.
        ],
    },
    networks: {
        sepolia: {
            url: "https://sepolia.infura.io/v3/",
            accounts: [process.env.KEY],
        },
    },
};
2
  • 1
    Man, I have been going nuts for 3 days trying to get these to compile. There simply isn't a whole lot of info out there on certain Solidity errors. BIG THANKS!!! May 30, 2023 at 22:36
  • You welcome :) dont forget to validate the answer if it fixed your problem
    – Saxtheowl
    May 30, 2023 at 22:42

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.