6

I'm trying to verify a contract I have compiled and deployed onto the network using Etherscan. The contract was compiled using truffle. How do I work out exactly which version of the solidity compiler to select on Etherscan?

8

I'm running Truffle 3.4.11 and running just: truffle version gives me the Solidity version as well:

truffle version                                                                                                                                                           
Truffle v3.4.11 (core: 3.4.11)
Solidity v0.4.15 (solc-js)
5

I managed to find a hacky way of doing this. Note - I was looking for more than just the version of solc. I was looking for the actual build of the compiler that solc was using (ie the commit used, night build number etc) so that I could could select it on EtherScan.

I have truffle installed globally so I ran which truffle which allowed me to eventually find (following symlinks) where truffle was stored on my mac: /Users/username/.nvm/versions/node/v7.7.3/lib/node_modules

From here it was easy to locate where the solc installation used by truffle is also stored. Relative to the previous path it would be in ./truffle/node_modules/solc

At this point - if you just want the version of the solc package you can look in package.json

If you want to go further and find the specific compiler version (like me) then take a look in wrapper.js and look for the var version variable declaration. It turns out this is a function which will return the compiler version name being used. Simply console.log(version()); on the next line and when you next run truffle test or truffle compile the solidity compiler build will be output into your console. For me this looked like:

var version = soljson.cwrap('version', 'string', []);
console.log(version());

Remember to return the wrapper.js file to its original state after you have got the info you need.

Note: This is a very hacky way of doing it. There's probably a better way but it was the first method I stumbled on. Even then - it didn't even help me get the contract verified on Etherscan, anyway.

  • 1
    The other methods suggested below are much more straightforward, I suggest editing this answer to reflect that there are much easier ways. – eladleb Mar 8 '18 at 9:10
4

You can look at the file ./node_modules/solc/package.json and see something like "solc@^x.y.z" where x.y.z is the version number that is being used.

4

The easiest way to get compiler version with truffle is to find it in your project directory ./build/contracts/YourContractName.json near the bottom of the file. It looks like,

 "compiler": {
    "name": "solc",
    "version": "0.4.18+commit.9cf6e910.Emscripten.clang"
  }
1

If you have npm installed with the -g flag, you can do this (omit the -g if you have it installed locally)

$ npm -g ls | grep solc └─┬ solc@0.4.18

That should be your version.

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.