Ethereum Smart Contract Development Part 2: Understanding Ethereum-related concepts

The original text was published in: Ethereum Smart Contract Development Part 2: Understanding Ethereum-related concepts

Many people say that Bitcoin is blockchain 1.0 and Ethereum is blockchain 2.0. On the Ethereum platform, various decentralized applications can be developed, which constitute the entire ecology of Ethereum. At present, Ethereum is the best underlying public chain for ecological construction in the blockchain world. This article will introduce the relevant concepts involved in the development of Ethereum in an easy-to-understand way, and lead you to get started easily.

Ethereum

Ethereum is a Turing-complete decentralized application platform built on blockchain technology. It allows anyone to develop, deploy and use decentralized applications in the platform through smart contract technology.

>  有没有感到和ios、Android平台有点类似?

Before the advent of Ethereum, the application of writing blockchain was like this: copy a copy of Bitcoin code, and then change the underlying code such as encryption algorithm, consensus mechanism, network protocol and so on. This was the case with many altcoins in 2013 and 2014, and a new coin was created by changing the Bitcoin code.

The Ethereum platform encapsulates the underlying blockchain technology, allowing blockchain application developers to develop directly based on the Ethereum platform. Developers only need to focus on the development of the application itself, which greatly reduces the difficulty.

>  目前围绕以太坊已经形成了一个较为完善的开发生态圈:社区支持、开发框架、开发工具等等。

smart contract

The explanations of smart contracts on the web are obscure. We can simply understand it as a special transaction contract that is event-driven, exists in the form of code, and is executable on the blockchain. It is a collection of code and data.

Smart contracts are very suitable for application scenarios that require high trust, security and durability, such as: digital currency, digital assets, voting, insurance, financial applications, prediction markets, property ownership management, Internet of Things, peer-to-peer transactions, etc.

At present, apart from digital currency, there are not many real applications. Just like when the mobile Internet was just emerging, there were various APPs from all walks of life, and the market of decentralized applications must have a bonus period in the early stage. Interested developers can seize the opportunity.

<!--more-->

Solidity

Solidity is a programming language similar to JavaScript, with the file extension ending in .sol . It is used for the development of smart contracts and can be compiled into Ethereum virtual machine bytecode and deployed on the underlying blockchain network of Ethereum.

EVM

EVM is the Ethereum Virtual Machine, the full name is Ethereum Virtual Machine. It is the runtime environment for Ethereum smart contracts.

> EVM是由以太坊节点提供。每个以太坊节点中都包含EVM
> Solidity之于EVM,就像Java跟JVM的关系一样
> 以太坊虚拟机是一个隔离的环境,在EVM内部运行的代码不能跟外部有联系

EVM runs on the Ethereum node. After we deploy the contract on the Ethereum blockchain network, the contract can run in the Ethereum network.

contract compilation

What runs on the Ethereum Virtual Machine is the bytecode of the contract. This requires us to compile the contract before deployment. > The solc compiler is recommended.

Ethereum client (node)

An Ethereum client is an Ethereum node. It provides account management, digital asset management, mining, transfer, deployment and execution of smart contracts, and more. For us developers, it is a developer tool.

Geth is a typical Ethereum client. The name Geth is short for the Go Ethereum open source project. It is a client software developed based on Go language and implemented the Ethereum protocol. Geth provides an interactive command console to operate various functions (APIs) of Ethereum through commands.

> Geth是全节点客户端,会一直同步以太坊区块链上的所有数据。目前数据量已经几十G,不久就会上百G。
> 在开发过程中,我们推荐使用以太坊区块链的私有链Ganache,免去同步以太坊全部区块数据的麻烦。在后续的文章中会介绍Ganache。

account

Accounts in Ethereum are divided into two categories:

  • External Account (EOA)

    This type of account is controlled by a public-private key pair (user), and the address of the external account that is not associated with any code is derived from the public key

  • Contract Account (CA)

    This type of account is an account allocated by a smart contract. It is controlled by the contract code and has a code associated with it. The deployment of the smart contract will publish the contract bytecode to the blockchain, and use a specific address to mark the contract. This address is for the contract account

Contract accounts store code, external accounts do not. Other than that, both types of accounts are the same for EVM.

Contract deployment is to deploy the compiled contract bytecode to the Ethereum blockchain network in the form of sending transactions through an external account (the actual deployment will be successful only after the actual miners produce blocks).

account

Transactions between external accounts and external accounts are merely transfers. However, various operations can be activated from external accounts to contract accounts.

run

After the contract is deployed, when you need to call the method of the smart contract, you only need to send a message (transaction) to the contract account. After the message is triggered, the code of the smart contract will be executed in the EVM.

Gas

Gas is the miner's fee. A certain amount of gas is charged for each transaction execution (packaged by miners) on Ethereum. The purpose of gas is to limit the amount of work required to execute a transaction, while paying for execution. When the EVM executes the transaction, the gas will be gradually consumed according to certain rules. No matter where the execution is, once the gas is exhausted, an out of gas exception will be triggered. All state modifications made by the current calling frame will be rolled back. If the execution ends and there is gas remaining, the gas will be returned to the sending account. Therefore, we need an external account with an ether balance to pay gas for transactions initiated.

Without this limit, there will be contracts that cannot be stopped (eg: infinite loop) to block the Ethereum blockchain network

Gas can be thought of as a unit of work, and the more complex the smart contract is (number, type of computational steps, memory occupied, etc.), the more gas is required. The smallest unit of gas is wei, 1eth=10^18wei=10^9gwei

GasLimit: The upper limit on the willingness to pay miner fees

GasPrice: miner fee unit price

gas = GasLimit * GasPrice

gas

Decentralized Application (Dapp)

The full name of Dapp is Decentralized App. The Ethereum community refers to applications based on smart contracts as decentralized applications. If we understand the blockchain as an immutable distributed ledger database, and the smart contract as the program that deals with the database, it is easy to understand Dapp. A Dapp not only has smart contracts, but also needs to have a friendly user interface and other business programs.

Truffle

Truffle is currently the most popular Dapp development framework. It can help us deal with a lot of tedious things, let us focus more on the development of smart contracts, and quickly start the process of coding - compiling - deploying - testing - packaging Dapp.

Summarize

Let's summarize now. Ethereum is the platform that allows us to easily develop decentralized applications using blockchain technology. In the application, we can use Solidity to write the smart contract that interacts with the blockchain. After the contract is written, we deploy the contract to the Ethereum node through an account with a balance, and run the contract (using the Truffle framework can be better help us do these things). For the convenience of development, we can use the Ethereum private chain Ganache to build a test network.

Note: In this article, in order to facilitate your understanding, some concepts are analogized, and some are not strictly accurate. However, I think that for beginners, it is not necessary to master every concept very carefully and accurately. Learning is a gradual and in-depth process. Many times we will find that after a period of time, we will have a different understanding of the same thing.

Smart contract development QQ group: 753778670

Smart contract development QQ group


There are currently several sets of video courses on blockchain practice (video + source code), if you need it, you can add me on WeChat (kuangwenjie) and send me a private message (paid):

  • "Blockchain" from zero construction of Ethereum (Ethereum) smart contracts to actual projects
  • Development of a decentralized Ebay blockchain project based on Ethereum & IPFS
  • HyperLedger Fabric

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324407812&siteId=291194637