Solidity Basics I

Learn about licenses, pragmas, imports, comments, smart contracts, and state variables in Solidity.

Solidity is a programming language that is used to write smart contracts for the Ethereum blockchain. It’s a high-level programming language that was designed by Gavin Wood and several co-founders of Ethereum. Solidity’s main characteristics are:

  • A procedural programming language: Specifies a series of steps to be followed in order to solve a problem. So, the program is designed as a sequence of commands or statements that must be executed one after another, in a specific order. 

  • A Turing complete language: Meaning that the program can be used to solve any problem that can be solved by algorithms. 

Its syntax is similar to that of JavaScript, making it easy for developers with a background in JavaScript to learn. It’s designed to target the Ethereum Virtual Machine (EVM), allowing developers to write secure and reliable decentralized applications (dapps) that implement self-enforcing business logic embodied in smart contracts.

The Solidity compiler takes the Solidity code and generates the bytecode that can be executed on the Ethereum Virtual Machine (EVM). It has become the most popular language for writing smart contracts on the Ethereum platform and has strong community support and a growing number of tools and frameworks for developing dapps.

The license

Smart contracts usually start with a Software Package Data Exchange (SPDX) comment. This is a special comment followed by a license identifier. For example:

//SPDX-License-Identifier: <license>

Here, <license> is a short string that uniquely identifies the license under which the smart contract is released (e.g. MIT). The comment can be located everywhere in the code, but the recommendation is to put it at the top of the file.

Pragmas

The pragma directive is an instruction used to specify the version of the compiler that should be used to compile the contract code. It’s typically the first line in a Solidity contract file and takes the form of: 

pragma solidity <version>;

Here, <version> is the version number of the compiler. The pragma directive (represented by the pragma keyword) is important because changes in the compiler and the language may introduce breaking changes that could cause errors in older code. By specifying the compiler version, the developer can ensure that their code will be compiled using a version that is known to be compatible. ...