1

I get the "Source file requires different compiler version (current compiler is 0.8.6+commit.11564f7e.Emscripten.clang)" at the first line:

pragma solidity ^0.7.0;

In truffle-config.js, I set a specific compiler version:

  compilers: {
    solc: {
      version: "0.7.6",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  },

But I still get the same error (at 0.8.6+). How do I fix this?

Thanks

3
  • If you run truffle version what does it show?
    – Ismael
    Jul 4, 2021 at 17:35
  • @Ismael Truffle v5.3.14 (core: 5.3.14), Solidity - 0.7.6 (solc-js), Node v14.15.4, Web3.js v1.4.0. Oddly enough, it says 0.7.6 for the compiler. But the error says compiler is on 0.8.6? (sorry for god awful format, idk why you can't format comments) Jul 4, 2021 at 21:14
  • 1
    @Ismael I fixed it by using 'pragma solidity >=0.7.0', but now I get 'file import callback not supported' for my github imports Jul 4, 2021 at 21:30

2 Answers 2

3

I went through this error recently.

This is happening because the compiler version configured on VS Code workspace is different from the version you want.

To fix that just right click on the error and select the option

Solidity: Change workspace compiler version (Remote)

It will open a drop-down with the available versions and you just pick the 0.7.6.

You can check this info on Solidity VSCode extension repository https://github.com/juanfranblanco/vscode-solidity/

0
1

If you are importing other contracts, those too need to be supporting the same pragma solidity version you are using on your main contract.

Another thing would be an issue with truffle, where the solc version you are using is not the same one that you are downloading when trying to run the compile command. this used to occur before but it might be the issue. To fix it you need to go inside the truffle node_modules package and install solc there with the version required. Or you can just re-install truffle globally from scratch and see if it fixes itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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