18th Lecture | Smart Contracts and Ethereum

Source: Internet
Author: User

In the previous article, we introduced the core technology of blockchain and introduced some projects. Each blockchain has its own features, however, and we'll explain each item in more detail next. Today we will talk about smart contracts and ethereum projects.

Today we start with the concept of smart contracts and talk about what is the Ethereum project and its history. Finally, we will introduce several wallets to you, hoping that through today's article, you can also try to write a simple smart contract on the Ethereum.

The concept of smart contracts

  Unlike the concept of contract in the legal sense, the contract in the blockchain domain expresses the computer protocol which can be "self-governing", which has the properties of self-executing and self-validating.

In a purely technical sense, a smart contract is equivalent to a state in which a computer code that has been set up in advance with logic and terms is activated, and the smart contract also provides a common user interface through which the user can interact with the user.

The concept of smart contracts was raised in the 1990s by a man who was Dr. Nick Szabo, who worked on smart contracts and digital money research, and Nick, in 1996, published a description of the smart contract in the Extopy Journal. He argues that a smart contract is a commitment that is specified by a digital form that contains a set of protocols that relate to multi-party execution.

From the definition, we can know that the intelligent contract consists of a number of protocols, which contain the user interface, can express the user's commitment, it can safely and effectively determine the relationship on the public network.

In other words, a smart contract is a transaction agreement that is processed by a computer and executes the terms of the contract, with the overall goal of satisfying the agreed conditions of the agreement, such as payment, collateral, and confidentiality agreements. This can reduce the losses caused by contract fraud, reduce the cost of arbitration and enforcement, and other transaction costs.

Let us give a practical example to explain that this April 9, a Shanghai Construction Bank branch opened the "unmanned bank", the bank is flooded with many machines and displays, smart Teller machine, VTM machine, foreign exchange machine, VR equipment and two machine people instead of the traditional counter.

Here the smart teller machine, foreign exchange robot many electronic equipment can be considered as a form of intelligent contracts, users in the banking business, such as handling large exchange transactions, business processes and logic basis has been set in the program, the user only need to follow the operation step by step, after completion can be obtained documents.

Here, "established business processes, robot-like human-computer interface, mutual consent" constitutes the concept of intelligent contracts, it even has a certain legal effect.

Saab proposes the concept of smart contracts, and the examples we cite are broad-sense concepts of smart contracts. The intelligent contract has many kinds of practice forms, but in the block domain The intelligent contract concept, we actually refer to blockchain-based this form.

In Saab's concept of smart contracts, the open network is mentioned, and we know that the basic requirements of open networks are Byzantine fault tolerance, as explained in the previous article, we know that the blockchain naturally has byzantine fault-tolerant characteristics. So if you practice the concept of a smart contract on a blockchain, the two will fit perfectly.

The first practice of the concept of the smart contract is bitcoin, the bitcoin script (bitcoin scripts) contains 5 standard trading scripts, the functions of these scripts not only provide the ordinary single payment, it also provides multi-party co-signed payment script, called multi-signature payment, Multi-signature payments can be seen as a smart contract under Saab semantics.

Besides bitcoin, the blockchain project that carries the concept of smart contracts is ethereum, and below, I'll focus on the Ethereum project.

Ethereum and its development history

  The goal of the Ethereum Ethereum project is to create a centralized next-generation Internet application platform called the Dapp platform.

These dapp are based on the Ethereum Smart Contract Virtual Machine development, compilation, deployment, and can customize the business logic, after deployment, the entire network is visible and automatic execution, ideally there is no downtime, review, fraud, third-party intervention situation.

    • Vitalik, founder of Ethereum at the end of 2013, presented an application that could run the Turing-complete (turing-complete) Form in the Bitcoin developer community, but this idea was not supported by the Bitcoin community.
    • In 2014, Vitalik with his own ideas, announced the establishment of the Ethereum project, began to raise funds in the first half of 2014, gathering some early developers, the same year in July for a 42-day ICO, a total of more than $18 million to raise bitcoins.
    • In July 2015, the first version of the Ethereum release, the main network officially launched, this phase of bug and design defects, many developers are using.
    • 2016 Ethereum released the second large version of Homestead, the user gradually more up, the same time also absorbed a lot of dapp developers.
    • In June 2016, the famous Black Swan event--thedao happened on Ethereum, which opened the ICO market and also caused the Ethereum community to fork, forming the Ethereum and Ethereum Classic two tokens.
    • In April 2017, ICO swept China, ERC20 provided a low-cost convenient and efficient way to raise funds, for the ICO to provide great convenience, in the digital currency bull market, ethereum price rose more than 10 times, January 2018 Ethereum Price exceeded $1000.

The core concept of Ethereum

  Ethereum core concepts include: Smart contract virtual Machine EVM and solidity programming language, account model, Ethereum and gas, trading and messaging.

1. Smart contract virtual Machine EVM and solidity programming language

The core concept of Ethereum is first the smart contract.

The smart contract consists of two parts: the development language, mainly solidity, and the solidity is very close to the JavaScript language in use, which greatly reduces the cost of learning for DAPP developers.

Dapp developers write code, the use of solidity compiled into hexadecimal bytecode, and then deployed to the EVM, that is, the contract broadcast to the entire network, and so on after the miners are packaged up to form a perennial running dapp.

The other part is EVM. EVM is an Ethereum smart contract virtual machine, and we can understand it as the execution engine for JavaScript, Python and other scripting languages.

It is a lightweight virtual machine isolated environment, it does not provide access to the local network, process, file system functions, it is more like a closed container, the container contains a running Dapp, can be seen as an inability to interact with the outside of the Docker Container.

Dapp can be triggered by requests or other events during the run, and then execute the appropriate logic, which is generated by transactions on the Ethereum, not events from the local operating system.

Dapp running process, each state changes, it means that the whole network synchronization update, the results are all consistent, there are two features:

    1. All Dapp calculations are well-known across the network, and once confirmed, they are almost impossible to forge and tamper with;
    2. This limits the capacity of the entire network because it has to go through a network-wide consensus.

2. Account Model

Ethereum does not use the UTXO model and is different from the bank account, which was designed by the Ethereum developers for their own account model.

There are two types of accounts on Ethereum, the first of which is called the contract account CA (contracts Accounts), and the second class is called the external Account EOA (externally owned Accounts).

The simple understanding is that the CA is an account for the smart contract code, EOA is a human account, so the CA can store and execute the smart contract code, its intelligence is EOA activated, it does not save and store the private key, the contract account can call other contracts.

EOA is an account that people directly control, can store the etheric currency, can send the transaction to the contract account, trigger the established logic. The EOA account is identified by the public key and is controlled by the corresponding private key.

When a contract account is called, the smart contract stored in it can be automatically executed in the miner's virtual machine and consumes gas, and if gas is insufficient it will trigger an "out of gas" exception and be terminated.

Both CA and EOA are considered status objects within the Ethereum (State objects), meaning that these accounts have their own status, Eoa have the status of the etheric currency balance, and the CA, in addition to the balance, has more contract storage status.

3. Ethereum and Gas

Gas is the fuel for performing smart contract operations, and every step of the smart contract consumes the Gas,gas is converted by Ethereum's platform token, the smallest unit is Wei,1eth equivalent to 10 of the 18 Wei.

The etheric coin can be mined by POW, and now the ethereum is mined mainly through the GPU. Dig up a block to Exchange 5 etheric coins, and there is a certain amount of transaction fees, as well as uncles block rewards. On April 6 this year, the famous miner chip maker Bit continent has developed ASIC specialized mining machine for ethereum, which is 2.5 times times more efficient than the GPU.

4. Transactions and messages

Trading on Ethereum differs from the Utxo transaction in Bitcoin, which refers to the process of sending a signed packet to another account by the EOA account, and the account status changes resulting from this process will be stored on the Ethereum blockchain.

In addition to the idea of trading on Ethereum, the message refers to the process of invoking a contract account with another contract account, which can be analogous to the function call process.

So if the Dapp on the Ethereum is triggered, there are two possibilities, the first is the trade trigger, and the second is the message trigger.

The difference between the two is that the former was initiated by EOA, which can only be initiated by other contract accounts.

The state change of state object is recorded by the ethereum consensus mechanism, the transaction and the message drive the change of state, so it is very convenient to build a global shared Dapp in an open network.

The smart contract in Ethereum has the features of full-network quasi-real-time synchronization, accurate execution, de-centering operation, low human intervention risk, and EVM and solidity provide a low entry threshold for global developers.

The main difference from Bitcoin

The Ethereum project is also known as the Blockchain 2.0 project, where 2.0 refers to the smart contract. So where is the intelligence in Ethereum compared to bitcoin? Let's take a look at it specifically.

In contrast to Bitcoin, Ethereum is not a simple digital currency project, it can provide the world's non-discriminatory blockchain intelligent contract application platform, which is based on the four core technical elements of blockchain, which is described in the previous article, namely peer network, consensus mechanism, account model, encryption module.

In addition to the above four technical elements, Ethereum also launched the evm--Ethereum Smart Contract virtual machine, and it also launched its own smart contract language solidity.

As a result, blockchain developers are divided into two categories because of the emergence of smart contracts. The first category is the low-level developers, mainly in C + + and go language-based full-node developers, they need to have a deep understanding of the blockchain technology modules.

The second category is the intelligent contract developers, the application developers, such developers do not need to understand the operation of the blockchain is very deep, only need to write solidity, understand the specification.

In addition to the concept of the Ethereum Smart contract, it also designed the following content.

    1. Research and implementation of their own POW mining algorithm--ethash, which is a memory-difficult mining algorithm.
    2. The uncles block excitation mechanism reduces the tendency of mining center. The Utxo model was canceled, the account model and world State were adopted, and the plasticity of data structure was provided.
    3. The gas mechanism is designed to avoid the situation of the program dying cycle consuming the whole network resources. The--casper of the POS consensus algorithm is researched and implemented to prevent nothing-at-stake attacks.
    4. Ethereum provides the ability to freely program in blockchain, and smart contracts allow everyone to develop their own dapp, which is not the ability to use Bitcoin as a mere digital currency.

Summarize

  In this article we introduce the concept of the smart contract and the Ethereum project, and explain the main differences with Bitcoin, some of the core concepts in Ethereum, the next we will explain the actual case of the smart contract, lead you to know some of the smart contract template, and by the way the other blockchain intelligent contract platform.

Reference Links:

Https://en.wikipedia.org/wiki/Smart_contract http://tech.ifeng.com/a/20180413/44947993_0.shtml

18th Lecture | Smart Contracts and Ethereum

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.