0

Hi guys I got this error when I try to compile using truffle develop.

    truffle(develop)> compile
Compiling your contracts...

    Compiling ./contracts/StarNotary.sol

    /mnt/d/Blockchain/Project2Test/node_modules/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.5.16+commit.9c3226ce.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version

pragma solidity ^0.6.0;
^---------------------^

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

then I changed the pragma into pragma solidity >=0.4.24 < 0.7.0; in ERC721.solin openzeppelin-solidity.

after that, I got this error

truffle(develop)> compile
Compiling your contracts...

    Compiling ./contracts/StarNotary.sol

/mnt/d/Blockchain/Project2Test/node_modules/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol:106:51: ParserError: Expected '{' but got reserved keyword 'override'
function balanceOf(address owner) public view override returns (uint256) {
  • There is an error message Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity ^0.6.0". Why you ignore it ? – Зелёный Jul 2 at 11:54
  • I never ignored that. When I got that error I changed the pragma into a particular range. Then I got an another error. – Sreesankar G Warrier Jul 2 at 11:57
  • /mnt/d/Blockchain/Project2Test/node_modules/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol:106:51: ParserError: Expected '{' but got reserved keyword 'override' function balanceOf(address owner) public view override returns (uint256) { this one – Sreesankar G Warrier Jul 2 at 11:57
  • The another error claim to syntax mismatch, you cant change pragma just like that without effects. – Зелёный Jul 2 at 11:59
  • 1
    You have two options 1) Change compiler version to match contract 2) Change contract syntax to much compiler requirements. – Зелёный Jul 2 at 12:00
0

The solidity version required by OpenZeppelin's contracts don't match the version configured in Truffle.

Either you can upgrade Truffle to use solc v0.6, or downgrade OpenZeppelin to version 2.5 that uses solc v0.5.

  • OpenZeppelin v3.0, v3.1 require solc v0.6
  • OpenZeppelin v2.5 require solc v0.5
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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