How to compile ERC-721 in OpenZeppelin Contracts - solc versions are not compatible

I am trying to use OpenZeppelin’s ERC-721 from the example on their website, using truffle.

In my truffle I have changed the solc compiler version to 0.6.0.

compilers: {
    solc: {
      version: "^0.6.0",    // Fetch exact version from solc-bin (default: truffle's version)
 }
    }
  }

When I try to “truffle” compile, I get the following errors:

CompileError: @openzeppelin/contracts/math/SafeMath.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.6.12+commit.27d51765.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version pragma solidity ^0.5.0; ^---------------------^ ,@openzeppelin/contracts/token/ERC20/ERC20.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.6.12+commit.27d51765.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version pragma solidity ^0.5.0; ^---------------------^ ,@openzeppelin/contracts/token/ERC721/ERC721.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.6.12+commit.27d51765.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version pragma solidity ^0.5.0; ^---------------------^

Error: Truffle is currently using solc ^0.6.0, but one or more of your contracts specify “pragma solidity ^0.5.0”. Please update your truffle config or pragma statement(s). (See https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration for information on configuring Truffle to use a specific solc compiler version.)

What I am not understanding is, if the underlying safemath implementations need older solc compiler, and the ERC-721 needs a newer solc compiler, How can anyone compile them? Why are the solc 0.6.0 not able to compile the older 0.5.0 solidity code?

Can someone please explain how to resolve such circular dependencies?

:computer: Environment
Truffle v5.1.58 (core: 5.1.58)

Solidity - ^0.5.0 (solc-js)

1 Like

What version of OpenZeppelin contracts are you using? Latest should work fine with solc ^0.6.0.

1 Like

I am using the latest version. Installed with npm @openzeppelin/contracts.

My question is the ERC-721 contract is using internally SafeMath and ERC721 and ERC20 all with 0.5.0 version. How can we compile this using solc 0.6.0.

It should be backward compatible, but it is not and throwing the above errors.

1 Like

Mind confirming what version number you see installed in your package.json? I can confirm to you that OpenZeppelin Contracts version 3.3.0 is all solidity >=0.6.0 <0.8.0.

1 Like

My contract version is - “@openzeppelin/contracts”: “^3.0.1”,

But when ERC-721 contract from Open zeppelin, uses another contract which use solidity 0.5 like safeMath for example, how can you compile this using solc 0.6?

1 Like

Mh that’s weird, OpenZeppelin Contracts 3.0.1 uses solidity ^0.6.0, I suggest you reinstall the library so you can move along from this issue.

Regarding your questions, I don’t think you can compile 0.5 contracts with solc 0.6.

1 Like

Hi @srinivasmangipudi,

Were you able to resolve?