23

I couldn't find a way to upgrade a version of truffle solidity compiler. Also curious how to see that information for deployed contracts in truffle console

  • 2
    Oh well, I would love how to downgrade solidity compiler in truffle. – soc1c Apr 12 '18 at 13:33

12 Answers 12

38

You can force truffle to use a specific solc version by installing that version directly in the truffle directory.

For example on Ubuntu the following with force truffle to use 0.4.15

$ cd /usr/local/lib/node_modules/truffle
$ npm install solc@0.4.15

truffle version will still show the default version but it will in fact utilize the updated version.

You can verify inside: /usr/local/lib/node_modules/truffle/package.json

...
"bundleDependencies": false,
  "dependencies": {
    ...
    "solc": "^0.4.15"
  },

Locations on Windows

%AppData%\npm\node_modules\truffle
%AppData%\npm\node_modules\truffle\package.json
  • 1
    didn't work for me – ulu Jan 13 '18 at 17:52
  • Could you please elaborate @ulu ? – Adam Lemmon Jan 14 '18 at 11:11
  • I had pragma 0.4.19 in my files, and truffle complained even after I followed your instructions. Had to change it back to 0.4.18. package.json has .19. – ulu Jan 14 '18 at 16:30
  • I'm trying the latest development version of solc, but I like the truffle testing framework. Is there a way to force truffle to use that one? Obviously the npm install path won't work -- it doesn't know about 0.4.20 at all. – Fred Douglis Jan 23 '18 at 15:24
  • PS. I see the comment in solcjs README about using the latest development snapshot. That seems to be what I want, but I don't know how to integrate that with truffle -- it seems better suited to a standalone js app that invokes a contract via solcjs. – Fred Douglis Jan 23 '18 at 15:33
10

If you're using ^v5.0.0 (including beta releases), you can bring your own compiler by adding this in your truffle config file (in this example it's set to 0.4.25):

module.exports = {
  ...
  compilers: {
    solc: {
      version: "0.4.25",
    },
  },
  ...
};

You can query the list of available compiler versions by running this:

truffle compile --list
  • 1
    This is awesome. What a great feature for them to add. – rhlsthrm Feb 1 at 0:28
9

After a couple of attempts, I've made it by uninstalling and installing truffle, exactly as described in here:

npm uninstall -g truffle
npm install -g truffle

That updated Truffle itself though, along with the compiler.

6

You need to upgrade your truffle to do that.

npm install -g truffle@X

For example, to get solc 0.4.11 support, install truffle 3.2.2 or above.

npm install -g truffle@3.2.2 

or

npm update -g truffle@3.2.2

2

Check your solc compiler version using the following command -

solc --version

Then you can use following commands to uninstall solc(solidity) compiler and install it again. It shall give you latest version(0.4.11) -

npm uninstall solc -g
npm install solc@0.4.11

Check the solc version after installing it again.

In order to see the information of contracts, once you login to truffle console and run "compile" and "migrate" one by one. After that, You just need to type your ContractName or ContractName.abi to get the contract information.

  • it doesn't provide information on solidity version. how do you know that it will start using global solidity compiler. also, you need to prove in your response to show what was the version of solidity compiler and the new one when you installed it globally. Did you try it? How did you verify the new bumped version? You are saying that abi compiled JSON contract should have a version. I've looked into it and I don't see where is the version of the compiler. – rstormsf Jun 9 '17 at 17:12
  • Edited the answer to check solc compiler version, you can check it before uninstalling it and then install it either globally or in the project directory as per your requirement. I did not try it again, but it should work this way. Let me know if this doesn't work for you? Also for contract information, I did not say that abi would have solc compiler version, please read carefully. I said typing contract name or contractname.abi in truffle console would give you information about the contract - like available functions, attributes etc. – Sanchit Jun 9 '17 at 17:32
  • Ok, My question is how to know which compiler version is being used in truffle. How to change it, how to read it. That's the exact question I'm asking. Please read my original question carefully – rstormsf Jun 9 '17 at 17:33
  • 1
    Truffle has solc compiler in it. and my question is how to figure out which solc version is being used in truffle. simple as that – rstormsf Jun 9 '17 at 18:26
  • 1
    @rstormsf Your question is about changing the version, not figuring it out. To figure it out, try truffle version or look in build/contracts/YourContract.json and scroll to the bottom to look at the "compiler" object which should say "name": "solc", "version": <the version>. – WBT Mar 8 '18 at 17:21
1

On your project root directory, there's a file named "truffle-config.js"

Inside this file, you can find a solc config, and uncomment version line, and then put your prefer version. (ex: 0.5.7)

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

After this, just compile and truffle will download that version of solc automatically!

$ truffle compile 
0

As @Adam Lemmon suggested, you can hardcode the version that the global truffle installation is using, or you can just update the version in the pragma solidity ^0.4.15; statement of your contract.

Note: This will only work if you are not inheriting from any other contracts. If the parent contracts use a higher solidity version, you'll get the compilation errors.

0

You can't specify version, but we can specify some params as well: http://truffleframework.com/docs/advanced/configuration#solidity-compiler-configuration

solc: {
  optimizer: {
    enabled: true,
    runs: 200
  }
}

https://github.com/poanetwork/poa-bridge-contracts/blob/master/truffle.js#L49

0

You need not to uninstall truffle just install your required version by these commands. For Ubuntu 16.04(suppose I want truffle v4.1.7):

sudo npm install -g truffle@4.1.7

Check truffle version:

truffle version

For any help with truffle commands:

truffle --help
0

I used next commands upgrade truffle when I want to compile solidity version: pragma solidity ^0.4.25;

npm uninstall -g truffle
npm install -g truffle@beta
0

Run uninstall and then install commands to get your Truffle and solc compiler upgraded to the latest version:

npm uninstall -g truffle
npm install -g truffle

Important: you may need to close the terminal and open it again to use the latest version.

Note: to check your current version execute:

truffle version
0

I messed around with manually changing the installed truffle package's solc dependency, however the versions weren't compatible, it wouldn't run my tests properly and it felt very hacky.

Instead I just installed the truffle package that naturally had a dependency on the solc version I wanted. In my case I wanted solc": "0.4.24" so I installed "truffle": "4.1.14".

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.