[Ethereum] How to specify a different Solidity version in a Truffle contract

contract-developmentsoliditytruffle

I've got a contract where I want to use <address>.transfer(), which was released in the latest Solidity version 0.4.10.

I have as the first line of my contract: pragma solidity 0.4.10; but when I compile I get Error: Source file requires different compiler version which pretty obviously means truffle is trying to compile my contract with not that version of Solidity. It still uses 0.4.8.

I installed 0.4.10 last night and solc --version shows 0.4.10.

So my question is, how do I change the version of Solidity in a truffle project? I've looked in the config file and the truffle docs and could not find this. I also cannot even find where 0.4.8 is installed (was assuming in truffle itself but it is not listed in truffle's package.json).

Best Answer

In Truffle version 5.0.0 (currently in Beta) you can specify a Solidity version in the truffle.js config file eg

module.exports = {
  networks: {
    ... etc ...
  },
  compilers: {
     solc: {
       version: <string>  // ex:  "0.4.20". (Default: Truffle's installed solc)
     }
  }
};

This is copied from the release details here

Related Topic