Solidity

Solidity Version Pragma

Solidity Version Pragma Main Tips

  • Pragmas in Solidity are used to specify certain conditions under which the source file can or cannot run.
  • The version pragma specifies what versions of Solidity a source file can work on.

Solidity Version Pragma

Solidity source files can have pragmas, which are used to reject versions of compilers, which may introduce changes that are incompatible.

Although the developers of Solidity try to avoid making changes that compromise the compatibility of compilers, sometimes changes like that are still made.

For this reason, it is advised that you add version pragmas to your source files.

This is example syntax of a version pragma in the beginning of a solidity source file:

pragma solidity ^0.4.0;

This pragma ensures that the source code is only meant for compiler versions that are not older than 0.4.0

The ^ symbol implies another condition – the source file will also not work on compilers past the version of 0.5.0

This version may possess changes that can compromise the compatibility between the source file and the compiler, while still allowing hotfixes for the version 0.4.x to be applied.

Keep in mind that the compiler version can have much more complex rules specified as well, the expression following those that are used by npm.

Note: versions that have major changes that possibly affect the compatibility with source files have versions of the form x.0.0 or 0.x.0

Read previous post:
Solidity Example Safe Remote Purchase

Solidity Example Safe Remote Purchase Main Tips This example of a smart contract demonstrates how to make a contract for...

Close