Solidity is a contract-oriented programming language used for writing smart contracts on the Ethereum blockchain. In this tutorial, we will discuss the syntax of Solidity.
Version pragma specifies the version of the compiler that should be used to compile the contract. It is recommended to use the latest version available.
Example:
pragma solidity ^0.5.2;
The above code will compile with a compiler version >= 0.5.2 and < 0.6.0.
Import statements allow us to use code from other Solidity files. There are three types of import statements:
Import all symbols from a file:
import "filename"
Import all symbols from a file and assign a symbol to the file:
import * as symbolName from "filename";
or
import "filename" as symbolName;
Import only selected symbols from a file:
import {symbol1 as alias, symbol2} from "filename";
Solidity supports several data types, which include:
The bool
type in Solidity can have the values true
or false
.
Operators:
!
(logical negation), &&
(AND), ||
(OR)==
(equality), !=
(inequality)Example:
bool x = true;
bool y = false;