Many students have been eager to try to join the blockchain development team, but they do not feel able to start. This article will introduce the obscure concepts involved in the development of Ethereum in a popular way based on the Ethereum platform, and easily lead you to get started.
What is Ethereum
Ethereum is a decentralized application platform built on top of blockchain technology. It allows anyone to build and use decentralized applications on the platform that run through blockchain technology.
Ethereum is the Android of blockchain. It is a development platform that allows us to write applications based on blockchain technology as well as the Android Framework.
Before Ethereum, writing a blockchain application was like this: copy the code of Bitcoin and change the underlying code like encryption algorithm, consensus mechanism, network protocol, etc. (this is what happens with many copycat coins, and change it to create a new coin). The Ethereum platform encapsulates the underlying blockchain technology, allowing blockchain application developers to develop directly on the Ethereum platform, as long as the developers focus on the application itself, thus greatly reducing the difficulty.
At present, a relatively complete development ecosystem has been formed around Taifang: with the support of the community, there are many development frameworks and tools to choose from.
Intelligent contract
What is a smart contract
Applications on Ethereum are called smart contracts, which are collections of code and data (states).
Smart contracts can be understood as contracts written in code (special transactions) that can be executed automatically (event-driven) on a blockchain.
In The Bitcoin script, we talked about the fact that bitcoin transactions can be programmed, but bitcoin script has a lot of limitations and a limited number of programs that can be written, whereas Ethereum is more complete (in computer science jargon, it’s called “Turing-complete”), Let’s write programs that can do almost anything just as we would with any high-level language (smart contracts).
Smart contracts are ideal for applications that require high levels of trust, security and persistence, such as digital currencies, digital assets, voting, insurance, financial applications, predictive markets, property ownership management, the Internet of Things, peer-to-peer transactions, and more. At present, in addition to digital currency, the real implementation of the application is not much (just like the mobile platform began to come out), I believe that in 1 to 3 years, all kinds of killer will slowly appear.
Programming language: Solidity
The default programming language for smart contracts is Solidity, with a file extension ending in.sol. Solidity is a JavaScript like language for developing contracts and compiling them into ethereum VIRTUAL machine bytecode.
Serpent is also a Python-like smart contract development language, though Solidity is recommended.
Browser-solidity is the Solidity IDE for browsers. Check it out for more Solidity articles in the future.
Operating environment: EVM
EVM The Ethereum Virtual Machine (EVM) is the environment for running smart contracts in Ethereum.
Solidity is to EVM what it is to THE JVM so that you can easily understand it. The Ethereum VIRTUAL machine is an isolated environment, and the code running inside EVM cannot be connected to the outside world.
EVM runs on ethereum nodes, and when we deploy the contract on the Ethereum network, the contract can run on the Ethereum network.
Compilation of contracts
The Ethereum VIRTUAL machine runs in the bytecode form of the contract and requires us to compile the contract before deploying, using the Browser-Solidity Web IDE or solC compiler.
Deployment of contracts
When developing applications on Ethereum, ethereum clients (wallets) are often used. In development, we usually don’t touch the concept of client or wallet. What is it?
Ethereum Client (Wallet)
The Ethereum client, which we can think of as a developer tool, provides account management, mining, money transfer, deployment and execution of smart contracts, and more.
EVM is provided by the Ethereum client
Geth is a typical client for ethereum development, based on the Go language. Geth provides an interactive command console that includes various ethereum functions (apis) through the command console. The use of Geth will be covered in a later article, but here you have an idea.
The Geth console is similar to the console in Chrome developer Tools, but runs inside a terminal. In contrast to Geth, Mist is the Ethereum client for a graphical operating interface.
How to deploy
Smart contract deployment involves publishing the contract bytecode onto the blockchain and identifying the contract with a specific address called the contract account.
There are two types of accounts in Ethereum:
- External account This type of account is controlled by a private key (controlled by a person) without any code associated with it.
- Contract account This type of account is controlled by their contract code and has a code associated with it.
Unlike Bitcoin, which uses a UTXO design, Ethereum uses a simpler account concept. Both types of accounts are the same for EVM.
The difference and relationship between an external account and a contract account is as follows: an external account can send messages to another external account or contract account by creating and signing transactions with its own private key. Sending messages between two external accounts is a value transfer process. But a message from an external account to a contract account activates the contract account’s code, allowing it to perform various actions (such as transferring tokens, writing to internal storage, mining a new token, performing some operations, creating a new contract, and so on). Only when the external account gives the order, the contract account will perform the corresponding operation.
Contract deployment is the deployment of the compiled contract bytecode to the Ethereum blockchain in the form of transactions sent from an external account (the actual deployment is not successful until blocks are produced by actual miners).
run
After the contract is deployed, when the method of the smart contract needs to be invoked, it only needs to send a message (transaction) to the contract account, and the smart contract code will be executed in EVM after the message is triggered.
Gas
Similar to cloud computing, there is a price to be paid for occupying blockchain resources, whether for simple money transfers or for deploying and executing contracts. . Ethereum uses the Gas mechanism for billing. Gas can also be thought of as a unit of work, and the more complex the smart contract (number and type of calculation steps, memory footprint, etc.), the more Gas is required to complete the run. The amount of Gas required to run a contract for any particular contract is fixed, determined by the complexity of the contract. The Gas price is determined by the person running the contract when he submits the request to run the contract to determine what he is willing to pay for the transaction: Gas price (in Ether) * Gas quantity.
The purpose of Gas is to limit the amount of work required to execute transactions while paying for execution. When the EVM executes a transaction, Gas is progressively consumed according to certain rules, regardless of where it is executed, and once the Gas is exhausted, an exception will be raised. All state changes made by the current calling frame are rolled back, and if there is Gas left at the end of execution, it is returned to the sending account.
Without this limitation, someone would block the network by writing contracts that could not be stopped (e.g., an endless loop).
So in effect (to string things together), we need an external account with an Ethereum balance to initiate a transaction (either a normal transaction or deploy and run a contract), at which time miners are charged for their work.
Test network: private chain
For those of you who are in a hurry, I don’t have ether. How do I develop smart contracts? The answer is to create your own private test network for Ethereum, often referred to as a private chain, which we can use as a test environment to develop, debug, and test smart contracts. With the aforementioned Geth, it’s easy to create your own test network, mining as much ether as you want without having to synchronize the entire blockchain data to the formal network.
Another way to create a test network is to use TestrPC, which is an Ethereum environment that emulated locally using memory, making it easier and faster to debug. And testrPC can help us create a test account with a pile of money at startup. Contract development can be tested in testrPC and then deployed to Geth.
Dapps: Decentralized applications
The Ethereum community calls smart contract-based applications Decentralized apps. If we think of blockchain as an immutable database, and smart contracts as programs that deal with databases, then it’s easy to understand dapps. A Dapp not only has smart contracts, but also needs a friendly user interface and other things.
Truffle
Truffle is a Dapp development framework that takes care of a lot of the little things that don’t matter and allows us to quickly start the code-compile-deploy-test-package Dapp process.
conclusion
To sum up, Ethereum is the platform that makes it easy to develop decentralized apps using blockchain technology. In this app, write smart contracts that interact with the blockchain using Solidity. Once the contracts are written, We need to use the Ethereum client to deploy and run contracts with a balance account (using the Truffle framework helps us do this much better). For development convenience, we can use Geth or TestrPC to build a test network.
Note: this article in order to facilitate everybody understanding, do the analogy to some concepts, some strict to is not accurate, but I also think for beginners, and there is no need to put each concept is very detailed and accurate, learning is a process of gradually thorough, many times we will find that after a while, we will have different understanding on the same thing.
Do you understand these concepts by the end of this article?
Blockchain in Simple terms – systematic learning of blockchain to create the best blockchain technology blog
WeChat pay
- By Tiny Bear
- Links to this article: Learnblockchain. Cn / 2017/11/20 /…
- Copyright notice: This article is published under a CC BY-NC-SA 3.0 license. Reprint please indicate the source!