Click on the asynchronous book, the top public account

Every day to share with you IT good books technology dry goods workplace knowledge

Section 1 Overview

For starters, you need to understand the basic concepts of ethereum development and how to build a complete decentralized application based on Ethereum such as a blockchain voting system.

Through study, you will master:

The basics of the Ethereum blockchain

Develop and deploy the software environment required for ethereum contracts

Write ethereum contracts in solidity

Use the Truffle framework to develop distributed applications

Use the console or web page to interact with the contract

Prior knowledge requirements for ethereum development

In order to successfully complete this course, it is desirable to have some basic understanding of the following techniques:

An object-oriented development language, such as Python, Ruby, Java…

Front-end development language: HTML/CSS/JavaScript

Use the Linux command line

Basic concepts of databases


Section 2 Introduction

We will build a Decentralized voting application. With this voting app, users can vote for specific candidates in a trustless distributed environment, and each vote is recorded on the blockchain:

A DApp (Dcentralized Application) is an Application that does not have a central server. Copies of the application can be run on hundreds of computers in the network, making it almost impossible for it to go down.

Blockchain-based voting is completely decentralized and therefore does not require the existence of any centralized organization.

Section 3 Development iteration

Covering the whole process of application development, we will gradually introduce concepts, languages and tools involved in blockchain application development through three iterations:

Vanilla: In the first iteration, we didn’t use any development framework, we just used NodeJS for application development, which helped us better understand the core concept of blockchain application.

Truffle: In the second iteration, we will use Truffle, the most popular decentralized application development framework. Using a development framework helps us improve development efficiency.

Tokens: In the third iteration, we will introduce tokens for voting applications — now everyone is calling them tokens — thanks to ICOs. Token is an indispensable incentive mechanism on the public chain, which is another significant feature that distinguishes blockchain applications from traditional centralized applications.

Why the voting app?

Voting was chosen as our first blockchain application because collective decision making — and voting in particular — is a core value proposition of Ethereum.

Another reason is that voting is the building block of many complex decentralized applications, so we chose voting as our first project to learn about blockchain application development.

Section four: Getting to know blockchain

If you’re familiar with relational databases, you know that a table can contain many rows of records. For example, the following table contains six transaction records:

In essence, a blockchain is first and foremost a Distributed database that maintains an ever-growing list of records. Now, let’s batch the data, say 100 rows per batch, and connect the storage batches together, like a chain?

remove
Click here to add caption

In a blockchain, a batch of multiple records is called a block, and each row of records in that block is called a transaction:

The original block, commonly known as the Genesis block, does not point to any other block.

imtamability

A striking feature of blockchain is that once data is written to the chain, it cannot be tampered with and rewritten.

In a traditional relational database, you can easily update a data record. But in a blockchain, once the data is written, it can’t be updated — so the blockchain is always growing.

So, how does blockchain achieve the immutable nature of data?

This starts with a Hash function — if you haven’t seen it yet, think of it as a digital fingerprint function: input anything of arbitrary length and output a stream of constant length (fingerprint). An important property of the hash function is that any slight change in the input will result in a change in the output. The hash value can therefore be used as a fingerprint of the content. You can click here to learn more about hash functions.

Since each block in the blockchain stores the hash value of the previous block’s content, if any block’s content is tampered with, the hash value of all blocks after the tampered block changes, making it easy to detect whether each block of the blockchain has been tampered with.

The challenge of decentralization

Once fully decentralized, there will be a large number of copies of blockchain (i.e., full nodes) on the network, and many things will become much more complex than in the previous centralized application environment. For example:

How do I ensure that all copies are synchronized to the latest state?

How to ensure that all transactions are broadcast to all the node computers that run and maintain copies of the blockchain?

How to prevent malicious participants from tampering with the blockchain

In the following courses, we will gradually understand the core ideas of decentralized applications and grasp how to build decentralized applications on Ethereum by comparing them with classic C/S architectures.

Section 5 C/S architecture is server-centric

The best way to understand the decentralized application architecture is to compare it to the familiar Client/Server architecture. If you are a Web developer, you should be familiar with the following diagram, which shows a typical Client/Server architecture:

The server side of a typical Web application is usually implemented in Java, Ruby, Python, etc. The front-end code is implemented by HTML/CSS/JavaScript. Then host the entire application in the Cloud, such as AWS, Google Cloud Platform, Heroku…. Or put it on a VPS host you rent. A user interacts with a Web application Server through a Client. Typical clients include browsers, command line tools (curl, wget, etc.), or API access code. Note that in this architecture, there is always a centralized Web server (or set of servers) with which all clients need to interact. When a client makes a request to the server, the server processes the request, interacts with the database/cache, reads/writes/updates the database, and then returns a response to the client.

This is the familiar centralized architecture. In the next section, we’ll look at some significant differences in a decentralized blockchain-based architecture.

Section 6 decentralized Architecture — Nodes equal to each other

The following chart shows the decentralized application architecture based on Ethereum:

You should have noticed that each client (browser) interacts with its own node application instance, rather than requesting services from a centralized server.

In an ideal decentralized environment, everyone who wants to interact with a DApp would need to run a full blockchain node on their computer or phone — in short, everyone would run a full node. This means that users have to download the entire blockchain before they can actually use a decentralized app.

But we don’t live in a utopia, and it’s unrealistic to expect every user to run a full node before using your app. But the core idea behind decentralization is to not rely on centralized servers. As a result, some solutions have emerged in the blockchain community, such as Infura, which provides public blockchain nodes, and Metamask, a browser plug-in. With these solutions, you don’t need to spend a lot of hard disk, memory, and time to download and run a full blockchain node, and you can take advantage of decentralization. Each of these solutions will be evaluated separately later in the course.

Section 7 Ethereum — World Computer

Ethereum is an implementation of a blockchain. In the Ethereum network, a number of nodes are connected to each other to form the Ethereum network:

Ethereum node software provides two core functions: data storage and contract code execution.

In each ethereum node, complete blockchain data is stored. Ethereum not only stores transaction data on the chain, but also the compiled contract code.

Ethereum full node also provides a virtual machine to execute the contract code.

Trading data

Every transaction in Ethereum is stored on the blockchain. When you deploy a contract, a deployment is a transaction. When you vote for a candidate, a vote is another deal. All of these transactions are open for everyone to see and verify. This data can never be tampered with.

To ensure that all nodes in the network have the same copy of data and are not writing any invalid data to the database, Ethereum currently uses proof of work (POW: “Proof Of Work” algorithms to secure networks, which use miners to mine for Consensus — synchronizing data to all nodes.

Proof of work is not the only algorithm to reach consensus, nor is mining the only alternative to blockchain. For now, it’s just a matter of understanding that consensus is the agreement of data across nodes, and POW is just one of many consensus-building algorithms that require miners to mine for trusted transactions in untrusted environments. Consensus is the end, POW is the means.

Contract code

Ethereum doesn’t just store transaction data on the chain, it can store contract code on the chain as well.

At the database level, blockchain is used to store transaction data. So where is the logic of voting for candidates, or retrieving the results? In the ethereum world, you can use

Solidity

Language to write the business logic/application code (i.e., Contract: Contract), then compile the Contract code into Ethereum bytecode and deploy the bytecode to the blockchain:

Other languages can also be used for writing contract code, but Solidity is by far the most popular option.

Ethereum virtual machine

The Ethereum blockchain not only stores data and code, but also contains a Virtual Machine (EVM: Ethereum Virtual Machine) within each node to execute the contract code — which sounds like a computer operating system.

In fact, this is at the heart of what sets Ethereum apart from Bitcoin: Virtual machines ushered in blockchain 2.0 and made it a developer-friendly platform for the first time.

JS development libraries

To facilitate building web-based DApps, Ethereum also provides a very convenient JavaScript library, Web3.js, which encapsulates the ETHEREum node API protocol, allowing developers to easily connect to blockchain nodes without having to write tedious RPC protocol packages. Therefore, we can directly import this library in common JS frameworks (e.g. Reactjs, AngularJS, etc.) to build decentralized applications:

remove
Click here to add caption

This article is excerpted from the asynchronous community by Xiaozhi, author of “Introduction to Ethereum Development: How to Build a Blockchain DApp Voting System”, click below to read the original article to see more


Stretch recommended

New book in February 2018

A blockbuster book for January 2018

Primary school students start learning Python, the closest programming language to AI: A Wave of Python books from Amway

Policy warming: Everyone is learning big data, a wave of good books recommended

Selenium Automation is a Python based test book for Selenium

Eight new books. Send one you like

AI | classic books (introduction to artificial intelligence which books to read?

Click on keywords to read more new books:

Python | | machine learning Kotlin Java | | | | mobile development robots contests | Web front-end | book list


Click on keywords to read more new books:

Python | | machine learning Kotlin Java | | | | mobile development robots contests | Web front-end | book list

Long press the QR code, you can follow us yo

I share IT articles with you every day.


If you reply “follow” in the background of “Asynchronous books”, you can get 2000 online video courses for free. Recommend friends to pay attention to according to the prompts to get a gift book link, free of charge asynchronous books. Come and join us!

Scan the qr code above and reply “follow” to participate in the event!

Read the article below to see more

Read the original