Pragma Solidity Version

whiteboard crypto logo
Published by:
Whiteboard Crypto

Pragma Solidity is a shortened way of saying “Pragmatic Information for Solidity” and it is usually followed by the version of Solidity you wish to use for the following contract.

Here is how you will see it often used in a smart contract:

pragma solidity 0.8.13;

This is usually the second line of code in a Solidity smart contract, following the SPDX License Identifier.

The keyword pragma can be used to other pragmatic information as well, including the abiencoder and STMChecker.

How to specify a range of solidity versions with pragma?

//the following line of code specifies ONLY compiler version 0.8.13
pragma solidity 0.8.13;

//the following line of code specifies 0.8.13 up until 0.9.0
pragma solidity ^0.8.13;

//the following line of code specifies 0.8.13 up until 0.9.0, including 0.9.0 as well
pragma solidity >0.8.13 <=0.9.0;

If you specify a source file as using version 0.8.13, then you must also compile it with version 0.8.13. Almost all IDEs and Compilers will not let you compile with a different version that you specified in the source code.

Currently the compiler will let you use multiple lines to specify the solidity version, however, it is not a best practice to do so.

Solidity versions are separated with a period, and ordered in this way:

  1. Major version
  2. Minor version
  3. Patch version

In the case of 0.8.13, this means that the major version is “0”, the minor version is “8”, and the patch version is “13”. You can view all the changes made to a version in the Github changelog.

It should also be noted that this line of code is only officially recognized in version 0.4.0 and up.

whiteboard crypto logo

WhiteboardCrypto is the #1 online resource for crypto education that explains topics of the cryptocurrency world using analogies, stories, and examples so that anyone can easily understand them. Growing to over 870,000 Youtube subscribers, the content has been shared around the world, played in public conferences and universities, and even in Congress.