Programming blockchain part 5: Solidity programming language

Solidity was developed by Gavin Wood, Christian Reitwiessner, Alex Beregszaszi, Yoichi Hirai and a number of other members of Ethereum allow to write smart contracts on the blockchain platform like Ethereum.

  1. Programming blockchain part 1: C ++ programming language
  2. Programming blockchain part 2: Javascript programming language
  3. Programming blockchain part 3: Python programming language
  4. Blockchain programming part 4: Java programming language

The final part of the blockchain programming series will refer to Solidity. For anyone who wants to learn how to create DAPPs (hierarchical applications) or access ICO games, learning about Solidity is a must. The following article will give you a basic overview.

Solidity programming language

Solidity was developed by Gavin Wood, Christian Reitwiessner, Alex Beregszaszi, Yoichi Hirai and a number of other members of Ethereum allow to write smart contracts on the blockchain platform like Ethereum.

Solidity is a neatly designed language with a syntax very similar to ECMAScript (Javascript). There are some key points to keep in mind in Ethereum Design Rationale, namely that we will work in a stack-and-memory model with the size of 32-byte instructions. EVM (Ethereum virtual machine) allows access to the ' stack ' program like the registration space where the memory addresses are attached to create the Program Counter loop (to control the sequence program), temporary "memory" expandable and "storage" permanently written to blockchain, and most importantly, EVM requires a total of determinism in smart contracts.

So before continuing, see the example of Solidity's basic contract. (Code is taken from github).

Run a simple loop in Solidity:

 contract BasicIterator 
{
address creator; // reserve one "address" -type spot
uint8 [10] integers; // reserves a chunk của lưu trữ cho 8-bit 10 không xác định Integers trong một mảng
BasicIterator function ()
{
creator = msg.sender;
uint8 x = 0;
// Section 1: Assigning values
while (x integers [x] = x;
x ++;
}}
function getSum () constant returns (uint) {
uint8 sum = 0;
uint8 x = 0;
// Section 2: Adding the integers in an array.
while (x sum = sum + integers [x];
x ++;
}
return sum;
}
// Section 3: Killing the contract
function kill ()
{
if (msg.sender == creator)
{
suicide (creator);
}
}
}

Now let's analyze!

Part 1: Specify value

In the first step, fill in an array called " integers " which contains 10 8-bit unsigned integers. This will be done through a while loop. Let's see what's happening inside the while loop.

 while (x  integers [x] = x; 
x ++;
}

Remember, we have assigned the value ' 0 ' to the integer x. The while loop goes from 0 to integers.length . Integers.length is a function that returns the maximum capacity of the array. So if you decide that an array will have 10 integers, the arrayname.length will return a value of 10. In the above loop, the value of x goes from 0-9 (<10) and also assigns the value of itself. it gives integer arrays. So at the end of the loop, integers will have the following values:

0,1,2,3,4,5,6,7,8,9.

Part 2: Add array content

Inside the getSum () function, the content of the array itself will be added. That will be done by repeating the same while loop above and using the "sum" variable to add content to the array.

Part 3: Finish the contract

This function ends the contract and sends the remaining amount in the contract to the contract creator.

When asked about the inspiration and motivation behind creating Solidity, Dr. Gavin Woods said:

'It [Solidity] is a sophisticated tool to develop contracts that can ultimately provide both developers and users with information about what the code has done. To help with this, I created NatSpec, a contract-friendly document format, and made it the best option in Solidity. I have also proposed a set of official validation languages ​​(not yet implemented) to maximize the types of tools that ensure accuracy can be implemented.

I introduce things as a best option for Solidity languages ​​to provide an abstract concept for LOGs, similar in form to function calls. The inspiration for that comes from the 'signal' of the Qt meta-object system.

A later feature that Christian R. and I found together was the function of modifying functions; Allow properties to be set as part of the function signature to make some modifications to the content of that function. This language is very suitable for contract-oriented programming ".

This article covered 5 languages ​​used for blockchain programming. In fact, there are many other languages ​​that you can use with the blockchain. If you are a programmer, the development potential is really endless. As the world is increasingly decentralized and blockchain is becoming a more mainstream component, the future for blockchain programming is definitely limitless.

See more:

  1. Here are the 3 most readable blockchain books
  2. This is why 10 years from now, every company will use blockchain
  3. What is Ethereum, Smart Contract technology and ICO technology?
Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile