Date:

Share:

A Beginner’s Guide To Solidity

Related Articles

Solidity is a high-level, object-oriented programming language for creating smart contracts on automated blockchain transactions. The language was created by the participants of the Ethereum project when it was proposed in 2014. This language is mainly used to execute smart contracts in the Ethereum blockchain.

According to its documentation, “Solidity is the language of curly braces. It is influenced by C ++, Python and JavaScript, and is designed to target the Ethereum Virtual Machine (EVM).”

Solidity is also considered a JavaScript dialect. This implies that if you know JavaScript, learning Solidity should be simple. Before we learn more about solids, let’s understand some basic blockchain terms.

Table of Contents

Ethereum Virtual Machine

The Ethereum Virtual Machine (EVM) is the runtime environment of an Ethereum smart contract. The Ethereum Virtual Machine focuses on providing security and enables machines all over the world to run programs.

Virtual machines actually create a layer of abstraction between the code and the machine that executes it. It is required to promote software mobility and ensure that programs are isolated from each other and their host.

The Ethereum Virtual Machine was created to serve as a runtime environment for Ethereum-based smart contracts.

Smart contract

A smart contract is a distributed program that responds to events by making business sense. Replacing money, providing services, opening up information controlled by digital rights management and other forms of data manipulation, such as renaming an asset title, are all possible outcomes of making a smart contract. Smart contracts are most often written in solidity.

Smart contract languages ​​like Solidity cannot be executed directly by the Ethereum Virtual Machine. Instead they are converted to low-level machine instructions called opcodes.

Now that you have an idea about EVM and a smart contract, we can continue to learn about solidity

Environment setting

Before installing Solidity, you need to make sure that Node.js and NPM are installed on your computer. To install node.js on your Linux (Ubuntu) you can follow this article.

Once you have successfully installed Node.js and NPM on your computer, you can continue to install a Solidity compiler as detailed below:

sudo npm install -g solc

The command above will install the Solcjs and make it available throughout the system. Now you can run

solcjs 

If all goes well, you will see something similar down in your terminal

0.8.9+commit.e5eed63a.Emscripten.clang

You can also use an online editor called Remix IDE to compile and run your Solidity code.

Reserved keywords

Here are the keywords stored in Solidity:

Summary after the nickname to apply
automatic case to fetch A copy of
Default Set final Unchangeable
Implements B news Give
Macro Match variable blank
of to get around partial promise
Reference Transferable Atom Degree of
static supporter Replace try
typedef Type of Do not check

Import other files in Solidity

Importing a file in Solidity is similar to JavaScript, to import a file you can simply write

import "file";

All the global icons from the “file” are imported into the current global range by the above statement. But if you want to create a new global icon someName with all the global icons from “File” as members, you can post

import * as someName from "file";

Just like other programming languages, Solidity supports both single-line and multi-line comments.

  • Start the line with // Include a single line note.
  • to start with /* And finish with */ Include a multi-line comment.
 
 

Variables in solidity

There are mainly two types of variables available in Solidity.

  • Local variables: Variables with values ​​that will do so persist Until the function is completed
  • State variables: Variables whose values ​​are stored in a permanent contract storage system

Status changes

State variables store the value permanently in the contract storage. Each method must have its own scope, and state variables must be declared outside each defined function.

Status changes.png

Local variable

The relation of a local variable is contained within the function, and cannot be retrieved outside it. These variables are typically used to store temporary values.

Local variable.png

Operators in Solidity

Operators are important in any programming language because they establish the foundation for programming. Similarly, Solidity’s functionality is incomplete without the use of operators.

Solidity supports the following types of operators:

  • Arithmetic operators
  • Relative operators
  • Logical operations
  • Bitwise operators
  • Task operators
  • Conditional operators

However in this article we are going to learn only 3 of them but in a future article I will try to explain them all 🙂

Arithmetic operators

These operators are used to perform mathematical operations.

sets off Mark Description
Essay + Used to add two operands
subtraction Used to reduce the second operand from the first
multiplication * Used to double the two operands
division / Used to divide the counter in the denominator
Modulus % Gives the remainder after dividing integers
extension ++ Increases the total value by one
down Decreases the total value by one

Relative operators

These operators are used to compare two values

sets off Mark Description
Equal == Checks whether two values ​​are equal or not, returns truth if equal, and vice versa
Not worth ! = Checks whether two values ​​are equal or not, returns true if not equal, and vice versa
bigger than > Checks whether the left value is large on the right or not, returns truth if it is large and vice versa
less than < Checks whether the left value is small on the right or not, returns true if small, and vice versa
Greater than or equal to > = Checks whether the left value is large and equal to the right or not, returns truth if it is large and equal, and vice versa
Less than or equal to <= Checks whether the left value is small on the right or not, returns true if small and equal, and vice versa

Logical operations

These operators are used to combine two or more conditions

sets off Mark Description
AND makes sense && Returns true if both conditions are true and false if one of the conditions or both are false
OR LOGICAL || Returns true if one or both conditions are true and false when both are false
Makes no sense ! Returns true if the condition is not met, otherwise false

This is only part 2 of Web 3.0 however in the future we will discuss more about the solids.

Summary

This is this article. I hope you found this article useful, if you need any help please let me know in the comments section.

Do you want to buy me coffee, you can do it Here.

Let’s connect Twitter and LinkedIn.

👋 Thanks for reading, see you next time

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Popular Articles