3

I've noticed in various smart contract tutorials that different versions of Solidity are declared at the top. I would assume that you would just use the latest but I've noticed that certain contracts seem to work on one platform don't work on another i.e. deploying the same contract via Remix & MetaMask vs Mist?

3

It's a safety feature.

It might help to think of the solc compiler as a possible source of defects. It's a way of stating the version of compiler that was used in development and testing.

Consider a situation in which a team has conducted painstaking testing at great expense. Then, a series of unfortunate circumstances leads to a compile using a newer compiler. They put it into production with the mistaken belief that it was thoroughly tested, but in reality, it's different and broken. Oops!

The compiler will throw an error if it doesn't match what the source file asks for.

pragma solidity 0.4.11; // version 0.4.11. Nothing else will do.

pragma solidity ^0.4.11; // version 0.4.11 or newer 

In my opinion, the ^ notation is convenient for informal development. The precise notation is required before extensive testing or release.

It basically says "this code was compiled with 0.4.11" and people can compile the source themselves and see that it matches exactly. Implicitly, if the version that was tested was compiled with something else, then "this" bytecode wasn't really tested at all.

Hope it helps.

1
  • Ah this makes perfect sense! I was thinking in terms of declaring that I'm coding in a certain version of Solidity language but actually it is declaring the version of the compiler that I've developed and tested the code with. And in the specific instance above as I had developed the code wth Remix using the latest compiler, Mist would not deploy as it cannot safely verify that the same result would occur from their version of the compiler. Jun 16 '17 at 23:54

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.