I am using solidity version "pragma solidity ^0.4.20;". When I checked JSON files of contract, compiler version shows :

"compiler": {
    "name": "solc",
    "version": "0.4.21+commit.dfe3193c.Emscripten.clang"

Still I am getting error :

Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version

Command 'truffle version' gives :

 Truffle v4.1.5 (core: 4.1.5)
 Solidity v0.4.21 (solc-js)
  • 2
    What are you doing specifically that triggers that error? Trying to run the Solc binaries? Dec 4 '18 at 13:15
  • I was deploying contract to privatenet. The contract was running fine and suddenly this error occurred. When I change pragma solidity ^0.4.20; to pragma solidity 0.5.0; error disappears. Even there is error, I am able to deploy contracts.
    – angelmaria
    Dec 4 '18 at 13:18
  • 3
    The error implies the installed Solidity compiler is version which is trying to compile your solidity code is v0.5.0. So the question I am asking is how are you triggering the compilation? Clearly solc-js is not being used since it appears to have the right version. Dec 4 '18 at 13:33
  • 1
    Like @ShawnTabrizi pointed out, we need to know how the compilation is triggered. Often this will happen because people have different truffle versions installed globally vs locally for the project. If you're compiling with the locally installed truffle, it may be a newer version that has 0.5.0, but not new enough that it has BYOC (bring your own compiler). Then when you do truffle version, it uses the global one which is the right version.
    – natewelch_
    Dec 4 '18 at 16:20

During solidity (solc) 0.5 releases the different frameworks like solc, truffle, web3, openzeppelin had a timeframe where some had a 0.5 compatible version released and some didn't. I think you could have changed specified the solc version like here (didn't try that) but meanwhile all of the mentioned fully support 0.5 (openzeppelin since 2 days ago at time of writing).

Consider doing the following

npm outdated
npm install [my-outdated-package] #repeat for all outdated packages
rm -R -f build #cleanup step (might not be necessary)
rm -R -f node_modules #cleanup step (might not be necessary)
npm install
truffle compile #(will still fail)

Check with truffle version in a terminal window at some other place (not project dir) if it matches the current release here otherwise do this:

npm uninstall -g truffle
npm install truffle

Usually you should avoid installing global packages but e.g. BlockCatIO/solidity-flattener requires that solc is installed globally because of certain features (installation described here). Remember to upgrade that one too.

When you then run truffle-compile you should still see errors because they changed the syntax of pragma (found that here).

So change:

pragma solidity ^0.4.20;

pragma solidity >=0.4.20;

I also recommend upgrading ganache-cli (I had problems running the tests with old version):

npm install -g ganache-cli

You might then still see compile errors but that's what makes v0.5 great because they made some improvements you should troubleshoot one-by-one

Here the Breaking Changes in Solidity 0.5.0

Doing this I got it compiling again :)


Thanks, I was using visualstudio editor and enabled an extension for solidity where compiler version was upgraded. By specifying the version of compiler in Editor resolved the issue for me.

  • What setting did you change? What value did you give it? How did you get to that setting? Jun 5 '20 at 4:01
  • 2
    @PhilipRego You probably figured it out, however, for anyone using a Mac: CTRL + Click anywhere within the contract file using your VS editor and select "Change Compiler Version", it will then display a list of compiler versions for your selection beginning with the latest. For windows you may need to right click.
    – SirLemuel
    Apr 7 '21 at 20:18
  • 1
    With Windows, WSL (Ubuntu) and VS Code I did just that: CTRL+right click in the editor, then Solidity: Change workspace compiler version (Remote), selected a version that was suggested for the particular project and it worked. May 12 '21 at 5:53

I would recommend using solc-select (https://github.com/crytic/solc-select), it will allow switching easily between solc versions.


Try format of compiler at first line of Contract .sol :- pragma solidity >=0.4.21 <0.6.0

It worked for me. Hope this helps,


I had the same issue and by doing following, my error disappeared.

The syntax change in pragma is giving error. just Change pragma solidity ^0.4.20; to pragma solidity >=0.4.20;.


Run npm install solc go to package.json check the version of solc after go to truffle.config.json replace he version make sure its the same as in package.json change it on sol ils too

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.