Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source file requires different compiler version : Truffle

I have written one simple smart contract in solidity and trying to migrate it with truffle.

$ truffle migrate
Compiling .\contracts\Election.sol...
Compiling .\contracts\Migrations.sol...

    /D/ethereum/electiondemo/contracts/Migrations.sol:1:1: 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.4.24;
    ^----------------------^

Compilation failed. See above.`enter code here`
Truffle v5.0.0 (core: 5.0.0)
Node v8.11.1

Solidity version is 0.5.0. Please find below the code for the smart contract:

pragma solidity ^0.5.0;

contract Election {
    // Read/write candidate
    string public candidate;

    // Constructor
    constructor ( ) public {
        candidate = "Candidate 1";
    }
}
like image 286
Vikas Banage Avatar asked Dec 30 '18 07:12

Vikas Banage


2 Answers

Got the solution : In truffle.js. You need specify solidity version

module.exports = {
   // See <http://truffleframework.com/docs/advanced/configuration>
   // for more about customizing your Truffle configuration!
   networks: {
       development: {
           host: "127.0.0.1",
           port: 7545,
           network_id: "*" // Match any network id
       }
   },
   compilers: {
       solc: {
           **version: "0.4.24"** // ex:  "0.4.20". (Default: Truffle's installed solc)
       }
   }
};

Same need to given in your smart contract

like image 60
Vikas Banage Avatar answered Sep 18 '22 03:09

Vikas Banage


Add the below line to truffle-config.js

{
  compilers: {
    solc: {
      version: "0.4.24" // ex:  "0.4.20". (Default: Truffle's installed solc)
    }
  }
}
like image 45
Prashant Kajale Avatar answered Sep 20 '22 03:09

Prashant Kajale