1
votes

The following error is shown when using compiling with truffle:

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
pragma solidity ^0.4.23;
^----------------------^
SyntaxError: 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
pragma solidity ^0.5.4;
^---------------------^
Compilation failed. See above.
Truffle v5.0.4 (core: 5.0.4)
Node v8.12.0
4

4 Answers

1
votes

The truffle that you have installed doesnot support solidity compiler 0.5.4, you may either try solving it by using compiler of 0.4.23 or higher as pragma solidity >=0.4.23 or upgrade the compiler that your truffle supports which is mentioned in this link

0
votes

You should declare solidity compiler version in truffle.js file.

  compilers: {
    solc: {
      version: '^0.4.23'
    }
  }
0
votes

Some things you can do,

  1. Open the file in VS Code . Right click on .sol file and click "solidity:download compiler". Then select the version that matches the version of solidity used in your contract (i.e written at top of the .sol file ). Then right click again on the .sol file and choose "solidity : Change the default workspace compiler to remote, local,...".From that choose "localNodeModule"

  2. Right click again on the .sol file and choose "solidity : Change the default workspace compiler to remote, local,...".From that choose "remote"

0
votes

Go to VS Code>File>preferences>settings there under left panel, u'll find extensions and in it u'll find solidity preferences. There choose remote.

With that the file will start using the mentioned version