1

I haven't worked with Truffle/Solidity for a while and I am trying to get my environment/toolchain configure correctly. I have some questions regarding the compiler config.

I was originally not setting the compiler config options in truffle-config.js and recently set it to 5.5 which appears as if it caused Truffle to download a new Docker image, and compilation seems to have slowed down, or at least running the full test suite is quite a bit slower.

I am working on an a project and have been setting the pragma as

pragma solidity ^0.5.5;

My truffle config block:

  // Configure your compilers
    compilers: {
    solc: {
      version: "0.5.5",    // 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: "petersburg"
      }
    }
  }
  }

And my solc output:

solc --version
solc, the solidity compiler commandline interface
Version: 0.5.12+commit.7709ece9.Darwin.appleclang

Does this look correct? Are there any obvious improvements?

Project repo: https://github.com/alanwilhelm/upgradeable_token

2
  • 1
    Can you include the link to github direct? URL shorteners are not necessary here and often are a source a problems.
    – Ismael
    Jan 23 '20 at 21:02
  • 1
    @Ismael Sure updated. Also updated the repo with a small crowdsale. I'm up to 68 passing tests now. I notice when I use a config for my compiler via truffle-config things compile and test very slowly. I think it is downloading a docker image with the correct solc version. I was commenting out the solc config in truffle-config during active development because it seems to use my local solc and move a lot faster. recommendations appreciated. thx
    – errata
    Jan 24 '20 at 0:00
2

Truffle is not using solc.

You can see what it IS using with

./truffle version

This is a little ambiguous, IMO.

pragma solidity ^0.5.5;

In practice, what I like to do is specify exactly what compiler to use for top-level contracts and ^ for inherited contracts and libraries. That way, the toolchain will emit an error at the first sign of an inconsistency.

For example:

pragma solidity 0.5.5;

import "./Something.sol";

contract MyContract is Something {
 ...
}

and

pragma solidify ^0.5.1;

contract Something {
  ...
}

That leaves no possibility of compiling, testing, deploying with inconsistent compiler versions and it will also save you a little time if you want to bump it up to a newer version at some point.

It will also force you to consistently select the right compiler when using tools like Remix. You'll be reminded - it's gotta be 0.5.5.

As an FYI, my understanding is that Truffle downloads solcjs the same way Remix does it, and this is why the installed solc compiler (standalone) is irrelevant to Truffle.

Hope it helps.

2
  • That's a great tip and the kind of info I am looking for. Thx!
    – errata
    Jan 24 '20 at 1:14
  • Also good point. It's using solc-js. Truffle v5.1.8 (core: 5.1.8) Solidity v0.5.12 (solc-js) Node v10.15.1 Web3.js v1.2.1
    – errata
    Jan 24 '20 at 1:16

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.