A complete guide to Solidity and its basics - Part 0
Solidity is one of the popular programming languages in the Web3 and Blockchain space that are used for writing smart contracts.?
Solidity is an object-oriented, high-level programming language for creating smart contracts on the blockchain that automate transactions. The language was created by participants to the Ethereum project when it was proposed in 2014.
This language is mostly used to make smart contracts on the Ethereum blockchain. According to its documentation, "Solidity is a curly-bracket language. It is influenced by C++, Python, and JavaScript, and is designed to target the Ethereum Virtual Machine (EVM)."
Solidity is also considered a dialect of JavaScript. This implies that if you know JavaScript, learning Solidity should be simple. Before learning more about solidity let's understand some basic terms of blockchain.
Ethereum Virtual Machine
The Ethereum Virtual Machine (EVM) is the Ethereum smart contract runtime environment. The Ethereum Virtual Machine is focused on providing security and allowing machines all around the world to execute programs.
Virtual machines effectively create a layer of abstraction between the code and the machine that executes it. It is required to promote software portability and to ensure that programs are isolated from one another and from their host.
Smart Contract
A smart contract is a decentralized program that responds to events by executing business logic. Smart contracts are often written in Solidity.
The exchange of money, delivery of services, unlocking of information controlled by digital rights management, and other forms of data manipulation, such as altering the name on a property title, are all possible outcomes of smart contract execution.
Now that you have an idea about EVM and Smart Contract, we can continue learning about the Solidity
?? You can?use an online editor called Remix IDE to Compile and Run your Solidity code
Reserved Keywords
Following are the reserved keywords in Solidity:
Importing other files in Solidity
Importing a file in Solidity is similar to JavaScript, to import a file you can simply write
import "file";
Comments in Solidity
Just like other programming languages, Solidity support both single-line and multi-line comments.
- Start the line with // to include a single-line comment.
- Start with /* and end with */ to include a multi-line comment.
// This is a single-line comment
/*
But this is a multi-line comment in Solidity
It is easy, right?
*/
领英推荐
Variables in Solidity
There are mainly two types of variables available in Solidity.
Local Variables: Variables with values that will persist till the function is completed
State Variables: Variables whose values are kept in a contract storage system permanently
State variable
State variables store the value permanently in the contract storage. Each method should have its own scope, and state variables should be declared outside of any defined functions.
Local Variable
A local variable's context is contained within the function, and it cannot be retrieved from outside of it. These variables are typically used to store temporary values.
Operators in Solidity
Operators are important in every programming language because they establish the groundwork for the programming. Similarly, the functionality of Solidity is also incomplete without the use of operators.
Solidity supports the following types of operators:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment operators
- Conditional Operators
Two examples:
Arithmetic Operators
These operators are used to perform mathematical operations.
Relational Operators
These operators are used to compare two values