Truffle – Set Specific Compiler Version in Truffle with ‘Source File Requires Different Compiler Version’ Error

compilertruffletruffle-compile

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

Best Answer

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/

Related Topic