How to use OpenZepplin Contracts (with Solidity version ^0.6.0) in Truffle?

I’m encountering an error while compiling a contract (with version >=0.4.21 <0.7.0) which imports the following contracts.

@openzeppelin/contracts/token/ERC721/ERC721.sol
@openzeppelin/contracts/utils/Counters.sol

which both have a solidity version (^0.6.0).

Here is the full contract used.

Here is the error while truffle compile:

Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity ^0.6.0"

:computer: Environment
truffle: 5.1.43
solc: 0.5.16
@openzeppelin/contracts: 3.1.0

I have tried the following approach to fix the issue. Is this an issue from truffle or am I missing something here?

1 Like

Hi @vasa-develop, go to your truffle-config.js file and change the compiler version to use 0.6.0

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

Thanks @DragonLord,

I believe it will actually need to be 0.6.2 or above as one of the dependencies needs 0.6.2.

Hi @vasa-develop,

Just wanted to follow up.
As you are using OpenZeppelin Contracts v3.x, the pragma for your contract should be ^0.6.2 as an earlier version of the compiler won’t be able to compile the contract.

With your imports import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol"; you should be able to have these as import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

There currently isn’t any access control on minting, which means anyone can mint a token.
https://github.com/filecoin-shipyard/meme-nft-token/blob/master/contracts/MemeMarketplace.sol#L15

To see AccessControl in action see the ERC721PresetMinterPauserAutoId contract:

2 Likes

Thanks for suggestions @abcoathup @DragonLord :slight_smile:

1 Like