To begin this tutorial, go ahead and create a file in the remix ide, and name it whatever you want. ”basicSyntax.sol” would be a conventional or preferred name.
Every Solidity source file contain a number of contract definitions, import directive(either importing a smart contract from a internal contract by way of inheritance or from an external source file.), SPDX License Identifier, most importantly pragma line or directives, struct, enum, function, error, constructors and constant variable definitions etc.
These are the necessary components that make up a smart contract.
We would address the most important basic syntax mentioned above, the syntax not mentioned will fall under the subsequent topic as they are a topic of its own.
These line of code are not validated because they are ignored and are in the comment tag,but it does include the supplied string in the bytecode metadata. You can choose to code them in or ignore them, but it is always professional to code them in They are usually added at the top of the code block or the file.
Trust in smart contracts can be better established if their source code is available. Since making source code available always touches on legal problems with regards to copyright, the Solidity compiler encourages the use of machine-readable SPDX license identifiers. Every source file should start with a comment indicating its license.
Here is an Example of what an SPDX License Identifier looks like:
// SPDX-License-Identifier: MIT
// or
// SPDX-Lincense-Identifier: UNLICENSED // If you do not want to specify a license or if the source code is not open-source, you will use the special value UNLICENSED.
The pragma keyword is essential in every contract, here is why ⬇️
Every smart contract in solidity must have a pragma line, which indicates that it is solidity and the version of solidity use are building your smart contract with, and the .version the compiler is to use.
pragma solidity >=0.4.0 <0.6.0
pragma solidity ^0.7.0;
// the code block above is a pragma line which indicates the version that the compiler should compile to.
// ">=0.4.0 <0.6.0" this indicates that the compiler is to compile to anything that is the version 0.4.0 or any thing greater than 0.6.0
/*This pragma directive ^0.7.0 tells that the source code is written for Solidity version 0.7.0 or anything newer within 0.7, but not including version 0.8.0.*/
contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}