1

I installed the latest version of truffle, solc, node and also installed new version of openzeppelin-solidity library in my project.

Changed the truffle-config.js to use new solc version. My contract inherits from the openzeppelin library. Now when i run truffle compile, it give me the following error.

Error parsing openzeppelin-solidity/contracts/ownership/Ownable.sol: ParsedContract.sol:8:1: ParserError: Source file requires different compiler version (current compiler is 0.5.2+commit.1df8f40c.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version contract Ownable { ^------^

Here are the versions for everything I'm using:

$truffle version Truffle v5.0.0 (core: 5.0.0) Solidity - 0.5.2 (solc-js) Node v11.4.0

$ solc --version solc, the solidity compiler commandline interface Version: 0.5.2+commit.1df8f40c.Linux.g++

openzeppelin-solidity package.json has this "_from": "openzeppelin-solidity", "_id": "openzeppelin-solidity@2.0.0", .... "version": "2.0.0"

Now the Ownable contract uses compiler version ^0.4.24, which would be the case for all the contracts in the library.

Any ideas why this is happening and how to fix this?

  • For current version of open-zeppelin (and definitely for earlier versions) - use Truffle 4.1.14 (or earlier). Truffle 5 relies on Solc 0.5.0, while open-zeppelin is still on Solc 0.4.24. – goodvibration Dec 27 '18 at 12:22
2

Current version of open-zeppelin (2.0.0) relies on solc version 0.4.24.

Current version of truffle (5.0.0) relies on solc version 0.5.0.

Between solc 0.4.x and solc 0.5.x there are breaking changes.

Previous version of truffle (4.1.14) relies on solc version 0.4.24.

So in order to use open-zeppelin in conjunction with truffle, set in your package.json file:

"devDependencies": {
  "truffle": "4.1.14",
  "openzeppelin-solidity": "2.0.0",
  ...
}

Alternatively, in truffle 5.0.0 onward, you can choose the desired version of solc.

For example, in order to configure truffle to use solc 0.4.24, add this in truffle-config.js:

compilers: {
    solc: {
        version: "0.4.24"
    }
}

See more details in Truffle 5.0.0 release notes for how to bring your own compiler.

  • Thanks for your answer. Would that mean I need to downgrade truffle to version 4.1.14 – Sowmya Kannan Dec 27 '18 at 12:43
  • Btw tried adding that line in package.json too but it didnt help, any suggestions? – Sowmya Kannan Dec 27 '18 at 12:49
  • @SowmyaKannan: You're probably installing truffle globally (and then using it globally). In this case, the answer is yes - you'll need to uninstall it (globally) and then reinstall an older version (4.1.14 in this case). But if you want to follow my way and install it locally, then it means that in order to run truffle you need to execute /node_modules/.bin/truffle from the path where you run npm (instead of truffle from any path). This should work on Windows. a general command line (one that should work on any OS) is node ./node_modules/truffle/build/cli.bundled.js – goodvibration Dec 27 '18 at 13:39
  • Ok, Thanks for that. I am using Fedora Linux. Will try and let you know. I still feel this is not the optimal way, but as of now we just have to wait till openzeppelin releases a truffle 5.0.0 compatible version or downgrade. – Sowmya Kannan Dec 27 '18 at 14:15
  • @SowmyaKannan: There is an alternative - you can set Truffle to work with Solc 0.4.24, I will add an explanation to the sanswer. – goodvibration Dec 27 '18 at 14:17

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.