18

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).

  • which truffle's version do you have? – Badr Bellaj May 2 '17 at 20:41
  • Latest version as of two days ago. 3.2.1 – JohnAllen May 2 '17 at 21:33
  • Struggeling with the same, found any solution? – vonGohren May 7 '17 at 10:56
  • No using send for now. Truffle is being updated soon fyi. – JohnAllen May 7 '17 at 16:45
  • I couldn't figure it out as well. How do we see which latest solc version is being used in truffle. – rstormsf Jun 9 '17 at 1:53
8

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

6

Truffle unfortunately doesn't allow you to select a different compiler version, apparently this is a result of the solc API not yet being stable, thus making it difficult to change version.

If you run truffle version it will output both the truffle, and compiler version.

$ truffle version
Truffle v3.4.9 (core: 3.4.8)
Solidity v0.4.15 (solc-js)

Updating truffle will get you the most up to date version it supports. It tends to lag behind solc itself somewhat, since it takes time to implement the latest version, though they've been quicker recently.

  • I only get one line when I run $ truffle version. It is: Truffle v2.1.2 – paulhauner Aug 24 '17 at 5:00
  • Printing the solidity version must be a more recent feature then. Why not update to truffle 3? – maurelian Aug 28 '17 at 15:52
  • 1
    I did update to truffle 3. It now shows my solidity version :) – paulhauner Aug 30 '17 at 0:36
0

You will have to update your truffle to do this. I've answered how to update your truffle here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.