1

getting compilation error

in console it is showing:

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/ERC721/extensions/ERC721URIStorage.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC721/ERC721.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC721/IERC721.sol (^0.8.0)
  • @openzeppelin/contracts/utils/introspection/IERC165.sol (^0.8.0)
  • @openzeppelin/contracts/utils/introspection/ERC165.sol (^0.8.0)
  • @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol (^0.8.0)
  • @openzeppelin/contracts/utils/Strings.sol (^0.8.0)
  • @openzeppelin/contracts/utils/math/Math.sol (^0.8.0)
  • @openzeppelin/contracts/utils/Context.sol (^0.8.0)
  • @openzeppelin/contracts/utils/Address.sol (^0.8.1)
  • @openzeppelin/contracts/utils/Counters.sol (^0.8.0)

----------------------------code------------------------------------------

pragma solidity <=0.8.0;

import "@openzeppelin/contracts/utils/Counters.sol";

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

import "hardhat/console.sol";

hardhat.config.js

solidity: { compilers: [ { version: "0.8.0", }, { version: "0.8.1", settings: {}, }, ], },

1 Answer 1

1

This is due to a version mismatch between the Solidity version pragma statement in your contract and the OpenZeppelin contract files. The OpenZeppelin contracts require a Solidity compiler version of 0.8.0 or higher, as denoted by ^0.8.0, while your contract file specifies a version less than or equal to 0.8.0 with <=0.8.0.

To fix, modify the pragma statement in your contract file lik this:

pragma solidity ^0.8.0;

You can also update your hardhat file & remove the additional compiler configuration for version "0.8.1"

solidity: {
  compilers: [
    {
      version: "0.8.0",
    },
  ],
},

Your Answer

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

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