Current location - Trademark Inquiry Complete Network - Futures platform - What is Ethereum? A guide to the development of Ethereum.
What is Ethereum? A guide to the development of Ethereum.
What is Ethereum? A guide to the development of Ethereum.

Many students have been eager to join the blockchain development team, but they feel that they have no way to start. Based on the platform of Ethereum, this paper will introduce the obscure concepts involved in the development of Ethereum in a popular way, so that you can get started easily.

What is Ethereum?

Ethereum is a decentralized application platform based on blockchain technology. It allows anyone to build and use distributed applications on the platform through blockchain technology.

Students who don't understand this sentence can understand that Ethereum is the Android in the blockchain, and it is a development platform that allows us to write applications based on blockchain technology like the Android framework.

Before the emergence of Ethereum, writing a blockchain application was like this: copy a bitcoin code, and then modify the underlying codes such as encryption algorithm, * * * * identification mechanism and network protocol. A lot of counterfeit money is like this, and a new coin will come out after the change.

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

At present, a relatively perfect development ecosystem has been formed around Ethereum: with the support of the community, there are many development frameworks and tools to choose from.

Intelligent contract

What is a smart contract?

The program in the Ethernet workshop is called smart contract, which is a collection of code and data (status).

Smart contracts can be understood as contracts (special transactions) that can be automatically executed on the blockchain (driven by events) and written in code form.

In the bitcoin script, we mentioned that bitcoin transactions are programmable, but there are many restrictions in the bitcoin script, and the programs that can be written are limited, while Ethereum is more complete (called "Turing integrity" in computer science terminology), which allows us to write programs (smart contracts) that can do almost anything like using any high-level language.

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, market forecasting, property ownership management, Internet of Things, peer-to-peer transactions and so on.

At present, there are not many real applications except digital currency (just like the mobile platform just came out). I believe that 1 to 3 years, various killers will gradually appear.

Programming Language: Reliability

The default programming language of smart contracts is Solidity, and the file extension starts with. Saul.

Solidity is a language similar to JavaScript, which is used to develop contracts and compile them into bytecode of Ethereum virtual machines.

There is also a smart contract development language that looks like Python: Serpent, but I suggest you still use Solidity.

Browser-Solidity is a Solidity IDE of a browser. You can click to have a look. We will introduce the solidity of language in more articles later.

Operating environment: EVM

EVM (Ethereum Virtual Machine) Ethereum Virtual Machine is the running environment of intelligent contract in Ethereum.

Reliability is like JVM to EVM, so everyone can understand it easily.

Ethereum virtual machine is an isolated environment, and the code running inside EVM cannot be connected with the outside.

EVM runs on Ethernet nodes. When we deploy the contract to Ethernet, the contract can run in Ethernet.

Preparation of contract

Ethereum virtual machine runs in the form of bytecode of contract, so we need to compile the contract before deployment. We can choose Browser-Solidity Web IDE or solc compiler.

Deployment of contract

When developing applications in Ethereum, Ethereum clients (wallets) are often used. Usually we don't touch the concept of client or wallet in development. What is this?

Ethereum client (wallet)

Ethereum client, in fact, we can understand it as a developer tool, which provides functions such as account management, mining, transfer, intelligent contract deployment and execution.

EVM is provided by Ethereum client.

Geth is a typical client used when developing Ethereum, which is developed based on Go language. Geth provides an interactive command console, which contains various functions (APIs) of Ethereum. We will introduce the usage of Geth later, and here is a concept first.

The Geth console is similar to the console in the Chrome browser developer tool, but it runs in the terminal.

Compared with Geth, Mist is an Ethereum client with a graphical operation interface.

How to deploy

The deployment of smart contracts refers to publishing the contract bytecode to the blockchain, and using a specific address to mark the contract, which is called the contract account.

There are two types of accounts in Ethereum:

External account

This account is controlled by a private key (controlled by a person) and is not associated with any code.

Contract account

This kind of account is controlled by its contract code and has related codes.

Unlike the design of Bitcoin using UTXO, Ethereum uses a simpler account concept.

For EVM, these two types of accounts are the same.

The differences and connections between an external account and a contract account are as follows: an external account can create and sign transactions with its own private key and send messages to another external account or contract account.

Sending messages between two external accounts is a process of value transfer. But the message from the external account to the contract account will activate the code of the contract account, allowing it to perform various operations (such as transferring tokens, writing into internal storage, mining new tokens, performing certain operations, creating new contracts, etc.). ).

Only when the external account gives an instruction will the contract account perform the corresponding operation.

The contract deployment is to deploy the compiled contract bytecode to the Ethereum blockchain in the form of sending transactions through external accounts (the actual deployment is only successful after the actual miners are shielded).

run quickly

After the contract is deployed, when the method of smart contract needs to be called, just send a message (transaction) to the contract account, and the code of smart contract will be executed in EVM after the message is triggered.

gas

Similar to cloud computing, taking up the resources of the blockchain (whether it is a simple transfer transaction or the deployment and execution of contracts) also requires corresponding expenses (there is no free lunch in the world, right! )。

Ethernet workshop adopts Gas mechanism to charge, and Gas can also be regarded as a workload unit. The more complex the intelligent contract is (the number and type of calculation steps, the memory occupied, etc.). ), the more gas is needed to complete the operation.

The amount of natural gas required to run any particular contract is fixed, which is determined by the complexity of the contract.

The gas price is stipulated by the person who runs the contract when submitting the request for running the contract, so as to determine the fee he is willing to pay for this transaction: gas price (denominated in Thai currency) * gas volume.

The purpose of Gas is to limit the amount of work required to execute a transaction while paying for the execution. When EVM executes a transaction, gasoline will be gradually consumed according to certain rules. No matter where it is executed, once the gas is exhausted, it will trigger an exception. All status changes made by the current call frame will be rolled back, and if there are gases left after execution, these gases will be returned to the sender's account.

Without this restriction, someone will write an endless contract to block the internet.

So in fact, we need an external account with an etheric balance to initiate a transaction (ordinary transaction or deployment operation contract), and the miners will charge corresponding workload fees during operation.

Yitaifang network

Students with anxiety want to ask, how can we develop smart contracts without Ethereum? You can choose the following methods:

Select official website Test Network Testnet of Ethereum.

In the test network, we can easily get free Ethernet coins, but the disadvantage is that it takes a long time to initialize the nodes.

Use private chain

Creating our own Ethernet private test network, also known as private chain, can be used as a test environment for developing, debugging and testing smart contracts.

It is easy to create your own test network through the above Geth, and you can dig as much as you want in the Ethereum, which also saves the whole blockchain data of the synchronous formal network.

Using Developer Network (Mode)

Compared with the private chain, under the developer network (mode), a developer account with a large balance will be automatically allocated for us to use.

Using a simulated environment

Another way to create a test network is to use testrpc, which is an Ethernet environment simulated by local memory, and it is more convenient and faster to develop and debug. And testrpc can help us create 10 test accounts with funds at startup.

When a contract is developed, it can be deployed to the Geth node after it passes the test in testrpc.

Update: testrpc has now been incorporated into the Truffle development framework and is now named Ganache CLI.

Dapp: decentralized application

The Ethereum community calls applications based on smart contracts decentralized applications. If we understand the blockchain as an unbreakable database and the smart contract as a program to process the database, it will be easy to understand Dapp. A Dapp not only has smart contracts, but also needs a friendly user interface and other things.

truffle

Truffle is the development framework of Dapp, which can help us deal with many trivial things and let us quickly start the process of writing code-compiling-deploying-testing-packaging DApp.

abstract

Now let's sum it up. Ethereum is a platform that allows us to develop decentralized applications conveniently by using blockchain technology. In this application, we use Solidity to write smart contracts that interact with the blockchain. After the contract is written, we need to deploy and run the contract with the balance account in the client of Ethereum (Truffle framework can help us do these things better). For the convenience of development, we can use Geth or testrpc to build a test network.

Note: In order to facilitate your understanding, this paper compares some concepts. Some concepts are not strictly accurate, but I also think it is not necessary for beginners to master every concept 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 different understandings of the same thing.