Pragma
- Pragma is generally the first line of code within any Solidity file. pragma is a directive that specifies the compiler version to be used for current Solidity file.
- Solidity is a new language and is subject to continuous improvement on an on-going basis. Whenever a new feature or improvement is introduced, it comes out with a new version. The current version at the time of writing was 0.8.18.
- With the help of the pragma directive, you can choose the compiler version and target your code accordingly, as shown in the following code example:
pragma Solidity ^0.8.18;
- Although it is not mandatory, it is a good practice to declare the pragma directive as the first statement in a Solidity file.
SPDX License List
- The SPDX (Software Package Data Exchange) License List is a list of commonly found licenses and exceptions used in free and open source and other collaborative software or documentation.
- The purpose of the SPDX License List is to enable easy and efficient identification of such licenses and exceptions in an SPDX document, in source files or elsewhere.
- The SPDX License List includes a standardized short identifier, full name, vetted license text including matching guidelines markup as appropriate, and a canonical permanent URL for each license and exception.
Contracts
- A contract in the sense of Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain.
- Contracts in Solidity are similar to classes in object-oriented languages. They contain persistent data in state variables, and functions that can modify these variables.
- Calling a function on a different contract (instance) will perform an EVM function call and thus switch the context such that state variables in the calling contract are inaccessible.
- A contract and its functions need to be called for anything to happen. There is no “cron” concept in Ethereum to call a function at a particular event automatically.
Question / Answer
Contracts in Solidity are similar to classes in object-oriented languages. They contain persistent data in state variables, and functions that can modify these variables.
The SPDX License List is a list of commonly found licenses and exceptions used in free and open source and other collaborative software or documentation.
pragma is a directive that specifies the compiler version to be used for current Solidity file.