Source file requires different compiler version when compiling with Truffle

Hello

I try to run my first contract :smiley: But run into some issues about truffle and don’t know anymore what I can try so I ask here.

:computer: Environment
Windows 10
truffle.config:

    module.exports = {
    networks: {
        development: {
         host: "127.0.0.1",     
         port: 8545,            
         network_id: "*",      
    },
    mocha: {
        // timeout: 100000
      },
      // Configure your compilers
      compilers: {
        solc: {
          version: "0.7.0",    //<==========CHANGED THAT from "0.5.1"
          docker: true,        
          settings: {         
           optimizer: {
             enabled: false,
             runs: 200
           },
           evmVersion: "byzantium"
          }
        }
      }
    };

package-lock.js:

{
  "requires": true,
  "lockfileVersion": 1,
  "dependencies": {
    "@openzeppelin/contracts": {
      "version": "3.3.0-solc-0.7",
      "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-3.3.0-solc-0.7.tgz",
      "integrity": "sha512-ewfLD9WpXQXQHhhaXKweECNDafWRKV3wmFp8FlXpkqG5cVtAvuwLJ5n/O3ziBsUWt6W64u5Dyy8mGnrffs5Qhw=="
    },
    "zeppelin-solidity": {
      "version": "1.12.0",
      "resolved": "https://registry.npmjs.org/zeppelin-solidity/-/zeppelin-solidity-1.12.0.tgz",
      "integrity": "sha512-dgjPPnTmx14hAbTeOpTKemDeDCDdwglS0nquOAJG8h5o9zlb43FZafQSrMlIUUSp1EisDZfehrp5loGEYXHZBA=="
    }
  }
}

:memo:Details
First I got this error:
@openzeppelin/contracts/token/ERC20/ERC20.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.5.16+commit.9c3226ce.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity >=0.6.0 <0.8.0;
^-----------------------------^

So I run:
npm install @openzeppelin/contracts@solc-0.7

After that I get a very simliar error:
CompileError: @openzeppelin/contracts//math/SafeMath.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.5.16+commit.9c3226ce.Emscripten.clang - note that nightly builds
are considered to be strictly less than the released version
pragma solidity ^0.7.0;
^---------------------^

After I changed the version in the truffle.config (see above):
Compiling your contracts…

Command "docker" not found. // CHANGED that to english in my own words
Error: You are trying to run dockerized solc, but docker is not installed.
    at Docker.errors (C:\just\path\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\compilerSupplier\loadingStrategies\LoadingStrategy.js:66:1)
    at Docker.validateAndGetSolcVersion (C:\just\path\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\compilerSupplier\loadingStrategies\Docker.js:82:1)
    at Docker.load (C:\just\path\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\compilerSupplier\loadingStrategies\Docker.js:18:1)
    at CompilerSupplier.load (C:\just\path\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\compilerSupplier\index.js:71:1)
    at loadParser (C:\just\path\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\profiler\loadParser.js:15:29)
    at Object.requiredSources (C:\just\path\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\profiler\index.js:19:1)
    at Object.sourcesWithDependencies (C:\just\path\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\index.js:87:43)
    at necessary (C:\just\path\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\index.js:69:1)
    at C:\just\path\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\workflow-compile\index.js:33:1
    at async Promise.all (index 0)
    at compile (C:\just\path\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\workflow-compile\index.js:23:1)
    at Object.compile (C:\just\path\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\workflow-compile\index.js:66:45)
Truffle v5.1.57 (core: 5.1.57)
Node v14.15.1

Think the last one is because of the last manual change in config^^ would like to not use docker…

Hope some one can help starting to making fun:)

:1234: Code to reproduce
Hope it is enough to understand what is going on.

1 Like

Hello, again sorry… found my fault by myself… the “true” in the truffle-config.js at docker should be false …

1 Like

Hi @MToken,

Welcome to the community :wave:

Glad to hear that you solved it yourself.

I recommend looking at: https://docs.openzeppelin.com/learn/developing-smart-contracts

You can also go through: Create an ERC20 using Truffle, without writing Solidity

You may also want to look at the following: Solidity learning resources

1 Like