去中心化背后的想法是不依赖单一/集中式服务器.
以太坊区块链到底是什么?区块链有两个主要组成部分:
所以基本上,区块链存储你的数据、存储代码并在 EVM(以太坊虚拟机)中运行代码。您将在以后的部分中了解有关 ByteCode 和 EVM 的更多信息。
为了构建基于 Web 的 Dapp,以太坊提供了一个方便的 JavaScript 库,称为 web3.js,它连接到您的区块链节点。因此,您可以将这个库包含在您著名的 js 框架中,如 reactjs、angularjs 等,然后开始构建。
If you notice the diagram , every client (browser) communicates with its own instance of the application. There is no central server to which all clients connect to. This means, in an ideal decentralized world, every person who wants to interact with a dapp (Decentralized Application) will need a full copy of the blockchain running on their computer/phone etc. That means, before you can use an application, you have to download the entire blockchain and then start using the application.
We don't live in an ideal world and it is unreasonable to expect everyone to run a blockchain server to use these apps. But the idea behind decentralization is to not rely on a single/centralized server. So, the community has come up with solutions (hosted blockchain servers, metamask etc.) where you don't have to spend lot of your hard disk and RAM downloading and running a full copy of the blockchain but also not compromise on the decentralized aspect. We will evaluate those options in the future lessons.
Now, what exactly is in the Ethereum blockchain? The blockchain has 2 main components:
So basically, the blockchain stores your data, stores the code and also runs the code in the EVM (Ethereum Virtual Machine). You will learn more about ByteCode and EVM in the future sections.
To build web based Dapps, Ethereum comes with a handy javascript library called web3.js which connects to your blockchain node. So you can just include this library in your famous js framework like reactjs, angularjs etc and start building.
One of the best ways to understand Ethereum is by comparing it with a traditional client/server architecture. If you are a web developer, the diagram on the right should make sense (You can still follow along if you are not aware of the web architecture). It is a high level client/server architecture of a simple web application.
A typical web application consists of server side code which is usually written in a programming language like Java, C#, Ruby, Python etc. The frontend code is implemented using HTML/CSS/Javascript. This entire application is then hosted on a hosting provider like AWS, Microsoft Azure, Google Cloud Platform, Heroku or a VPS.
Users interact with the web application using a client such as web browser, curl/wget (command line) or through an API. Note that there is one web application which is centralized and all the clients interact with this one application. When a client makes a request to the server, the server processes the request, interacts with the database and/or cache, reads/writes/updates the database and returns a response to the client.
The Ethereum Virtual Machine (EVM) is a simple but powerful, Turing complete 256bit Virtual Machine that allows anyone to execute arbitrary EVM Byte Code. The EVM is part of the Ethereum Protocol and plays a crucial role in the consensus engine of the Ethereum system. It allows anyone to execute arbitrary code in a trust-less environment in which the outcome of an execution can be guaranteed and is fully deterministic.
When you install and start the geth, parity or any other client, the EVM is started and it starts syncing, validating and executing transactions.