Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify “pragma solidity ^0.8.0”

Viewed 5383
4 Answers

Omit the "^". Not version:"^0.8.0".

compilers: {
       solc: {
           version: "0.8.0"  
       }
}

Uncomment this line from truffle-config.js:

compilers: {
  solc: {
    version: "0.8.10",  // <-- this one
    .
    .
    ...

@Yilmaz is correct that the version needs to be modified. Change the truffle-config.js file to the correct compiler version. Make sure that you have a version set. I had the same error because the version was not set. If your file looks like this:

compilers: {
  solc: {
    // version: "0.5.1",    // 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"
    // }
}

Change it to something like this:

compilers: {
  solc: {
    version: "^0.8.0"
}

If you're using windows change your "truffle.js" file name to "truffle.config.js" and inside your truffle config file add this line of code if it doesn't exist

  compilers: {
solc: {
  version: "0.8.0" 

make sure don't use "^" in version:"0.8.0"

}
  }
Related