7 - Pragma Version
Version Pragma: This indicates the specific Solidity compiler version to be used for that source file and is used as follows: pragma solidity x.y.z;
where x.y.z indicates the version of the compiler.
-
Using the version pragma does not change the version of the compiler. It also does not enable or disable features of the compiler. It just instructs the compiler to check whether its version matches the one required by the pragma. If it does not match, the compiler issues an error.
-
The latest compiler versions are in the
0.8.z
range -
A different
y
inx.y.z
indicates breaking changes e.g.0.6.0
introduces breaking changes over0.5.z
. A differentz
inx.y.z
indicates bug fixes. -
A
^
symbol prefixed tox.y.z
in the pragma indicates that the source file may be compiled only from versions starting withx.y.z
untilx.(y+1).z
. For e.g.:pragma solidity ^0.8.3;
indicates that source file may be compiled with compiler version starting from0.8.3
until any0.8.z
but not0.9.z
. This is known as a “floating pragma.” -
Complex pragmas are also possible using
>
,>=
,<
and<=
symbols to combine multiple versions e.g.pragma solidity >=0.8.0 <0.8.3;
- Version Pragma
- Solidity Compiler Version
pragma solidity x.y.z
- Used vs. Specified
- Formats: Simple, Complex, Floating
- Affects: Features, OPtimizations, Security