4

Where is the main difference between:

pragma solidity ^0.4.24; and pragma solidity 0.4.24;

Why would I use one or the other? Advantages / Disadvantages?

What effect will it have in the future when I deploy the smart contract to the blockchain?

3
  • 1
    look at this is related: ethereum.stackexchange.com/questions/45231/…
    – qbsp
    May 31, 2018 at 9:08
  • Thanks for your link from which I take the information to lock the version is best practice. Does pragma solidity 0.4.24; lock the version?
    – Senju
    Jun 1, 2018 at 5:51
  • 1
    yes it does. If you use ^ will be 'open'
    – qbsp
    Jun 1, 2018 at 5:58

3 Answers 3

1

As per the Version Pragma section of the documentation:

The version pragma is used as follows:

pragma solidity ^0.4.0;

Such a source file will not compile with a compiler earlier than version 0.4.0 and it will also not work on a compiler starting from version 0.5.0 (this second condition is added by using ^).

So in your example,

pragma solidity 0.4.24; will work on any compiler from 0.4.24 and upwards, whereas

pragma solidity ^0.4.24; will compile on any compiler from 0.4.24 (inclusive) up to 0.5.0 (not inclusive.

However, note that this is only for compiler compatibility. Once you've compiled your contract, it's no longer in Solidity, so you can deploy it in the future without worrying about compatibility.

2
  • As for pragma solidity ^0.4.24; I understand. However, does pragma solidity 0.4.24; really specify 0.4.24 and upwards? Since when I use pragma solidity 0.4.0; it throws an error when compiling: SyntaxError: Source file requires different compiler version (current compiler is 0.4.24+commit.e67f0147.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version pragma solidity 0.4.0; ^--------------------^ Compilation failed. See above. As in your explanation it should be all right since 0.4.0 would include every higher compiler version?
    – Senju
    Jun 1, 2018 at 5:49
  • @Senju I have the same error as you.
    – Gqqnbig
    Feb 21, 2021 at 7:08
0

Lock pragmas to specific compiler version

Contracts should be deployed with the same compiler version and flags that they have been tested the most with. Locking the pragma helps ensure that contracts do not accidentally get deployed using, for example, the latest compiler which may have higher risks of undiscovered bugs. Contracts may also be deployed by others and the pragma indicates the compiler version intended by the original authors.

// bad
pragma solidity ^0.4.4;


// good
pragma solidity 0.4.4;

Solidity Documentation: Version Pragma

The version pragma is used as follows:

pragma solidity ^0.4.0; 

Such a source file will not compile with a compiler earlier than version 0.4.0 and it will also not work on a compiler starting from version 0.5.0 (this second condition is added by using ^).

0

The ^ symbol means you can compile using any version between the declared version through to the next whole number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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