A classic web application architecture B/S structure for web application development is taken as an example:
Generally speaking, after developing web applications, we will deploy web services to the public network. Now the popular way is to deploy them to the cloud VPS.No matter what load balancing and containerization technologies we use on the server side, or whether the client user uses a browser or an API constructor.In essence, all customers will access the application through the HTTP interface exposed by the server we deploy.On the server, the web application we write will perform some data operations, such as CRUD operations on the database or cache, and finally feed the results back to the client.
This B/S architecture is so popular because it is suitable for most application scenarios.However, there are exceptions. When users or service providers think that data is more valuable than applications, or service providers want to provide data services and effectively control users' right to write data.At this time, the application based on B/S structure will appear inadequate.
Unlike centralized web applications, blockchain uses a set of open source network specifications to provide real-time sharing and synchronization of data P2P.End customers can access a client device to the blockchain P2P network at any time. Based on standard protocols, the blockchain terminal will synchronize to the latest data in real time.In this data service, there is no longer a centralized server, which is the so-called "peer-to-peer centerless" feature.
Dapp is a web application based on blockchain, which is different from the traditional web service with B/S structure. Dapp fully absorbs the feature of blockchain "peer-to-peer without center" and adopts the structure of Browser/Blockchain.For the service provider, it is only necessary to synchronize the data to the blockchain and define a set of detailed data writing rules.The calling, reading and presentation logic of the data is completely defined by the user of the data.This not only ensures the credibility of the data through the blockchain, but also enables different data users to realize different Dapps on demand to mine the value of the data bb.Unlike centralized web applications, blockchain uses a set of open source network specifications to provide real-time sharing and synchronization of data P2P.End customers can access a client device to the blockchain P2P network at any time. Based on standard protocols, the blockchain terminal will synchronize to the latest data in real time.In this data service, there is no longer a centralized server, which is the so-called "peer-to-peer centerless" feature.
The following figure shows a typical Dapp architecture:
What we want to achieve Dapp
What we want to achieve is a note board application based on blockchain.The page rendering is as follows:
Users can add new notes or modify existing notes on the note board. All users who have opened the Dapp in the browser can see the update of the note and the notice of the note being updated synchronously.
This is a Dapp that is relatively simple to implement. This document will introduce its implementation process in detail.
Introduction to Label Board Dapp
The Dapp is mainly composed of two parts, including the smart contract deployed in the Ethereum network and the web application that relies on the smart contract to be responsible for business function interaction.The smart contract is developed by solidity, while the web application does not have a back-end server, but directly calls the Ethereum node interface, so it is directly developed by javascript and uses the react framework.
The call relationship between Dapp components is shown in the figure below:
Contract gatewayIt is the application middle layer created by the super chain BaaS platform for Ethereum network.In the past development, if you want to communicate with the Ethereum node, you need to use web3 and other libraries to carry out a series of complex processes, including nonce management, transaction packaging and encapsulation, transaction result analysis, etc., which will waste developers' time on meaningless data processing.The contract gateway is designed with RESTful API. Developers only need to pay attention to their own business logic without considering the underlying complex transaction management, which greatly improves the efficiency of development and reduces the burden on developers.
The note board application we want to develop is relatively simple. Its core function is to store the text notes created by users on the blockchain.There are only three key use cases to be realized:
User creates a new note
The user clicks Add, writes the note title and the note content in the editing window, and clicks "Link".The application saves the notes (note title, note content), and then closes the editing window.
User update memo
The user clicks the memo to be updated, modifies the title or content of the memo in the editing window, and clicks "Link".The application updates the note (note title, note body), and then closes the editing window.
Users view all notes
When you open the application, you can see all the notes on the chain, even the tabs.Notes are divided into note topics and note contents. Due to limited space on the note board, each note topic and body can only display up to 20 characters.The user can click a note to open the editing and updating panel to view all the contents.