Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to start the bytom DAPP buffer server

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to start the bytom DAPP buffer server". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

From the DAPP released so far, the DAPP architecture can be roughly divided into three types: plug-in wallet mode, all-node wallet mode and compatibility mode.

The plug-in wallet mode communicates with the block chain node through the RPC protocol through the browser plug-in that encapsulates the wallet. The plug-in will inject the Web3 framework into the DAPP front-end page at run time, and then DApp communicates with the block chain node through Web3.

The full-node wallet mode requires the project side to synchronize and hold a block chain node and provide a browser environment to interact with the user.

Compatibility mode can be used at the same time under plug-in wallet and full-node wallet, that is, the above two methods can be switched freely, and the security performance is relatively high.

The architecture pattern of the original chain DAPP is somewhat similar to the plug-in wallet pattern of the account model DAPP, which is composed of the DAPP front end, the plug-in wallet and the contract program, in which the plug-in wallet needs to connect to the decentralized blockchain server blockcenter, which is mainly used to manage the information related to the plug-in wallet. In addition, the original chain is the block chain system of the UTXO model, and the contract program exists in the stateless UTXO. If we want to implement such a specific DAPP, we need to do some more logical processing in the front end and back end.

1. Write, compile, and instantiate smart contracts to write smart contracts

Compared with the original chain, the virtual machine is Turing complete and can theoretically realize the operation that any Turing computer can achieve. As an intelligent contract language of original chain, Equity can implement many typical financial model cases by using Equity language, but in order to solve the problem of downtime, the upper limit of handling fee is also set, so users make a tradeoff when designing the contract.

The contract template is structured as follows:

Contract contract_name (...) Locks valueAmount of valueAsset {clause clause_name (...) {... Lock/unlock...}...}

Equity grammatical structure is simple, the meaning of the sentence is clear, children's shoes with development experience can basically understand the meaning of the contract. Writing an intelligent contract can refer to the introduction of the Equity contract, where the syntax and compilation methods of the Equity language are introduced in detail. In addition, the document also introduces some typical template contracts, developers can refer to their own needs.

Compile and instantiate the contract

The compilation contract currently supports two ways, one is to use the Equity compilation tool, and the other is to call the RPC interface compile of the compilation contract in the original chain. The purpose of contract instantiation is to lock the contract script according to the parameters set by the user. Compiling and instantiating the contract can refer to the instructions of compiling and instantiating the contract. This document not only introduces the parameter construction description of the contract, but also explains in detail the steps of compiling the contract. The compiler and related tools are located in the Equity compiler and are developed in the go language, and users can download the source code and compile it.

Examples of tool compilation and instantiation are as follows:

/ / compile./equity [contract_name]-- bin// instance./equity [contract_name]-- instance [arguments...] 2. Deployment contract

To deploy a contract, send the contract transaction. Call the build-transaction API of the original chain to send a specified number of assets to the contract program. You only need to set the receiver control_program in the output output to the specified contract. Users can refer to the locking contract section in the contract transaction description, and the structure of the transaction can be referenced according to the description in the document. If the contract transaction is successfully sent and the transaction has been successfully linked, you can find the UTXO of the contract by calling the API API list-unspent-outputs.

The deployment contract transaction template is roughly as follows:

{"actions": [/ / inputs {/ / btm fee}, {amount, asset, spend_account / / spend user asset}, / / outputs {amount, asset, contract_program / / receive contract program with instantiated result}],...} 3. Build DAPP architecture

Bytom's blockcenter server is an officially developed decentralized plug-in wallet server, which developers can call according to the relevant API interface. The overall DAPP framework model of the original chain is as follows:

DAPP front end

Building the DAPP front end mainly includes two aspects: one is the interaction between the front end and the plug-in wallet, the other is the front end logic processing, and the interaction with the buffer server. The plug-in wallet is a window to communicate with the blockchain node server. In order to communicate with the blockchain node, a DAPP needs to interact with the background server node with the help of the plug-in. Biyuan plug-in wallet in addition to interacting with the background server, but also contains some local business logic processing interface API, the details can refer to the DAPP developer wizard. Because the original chain is a block chain system based on the UTXO model, the transaction is a structure composed of multiple inputs and multiple outputs, and the positions of the input or output of the transaction need to be arranged in order, so the development of DAPP needs some logic to build the transaction. In addition, the calculation of the quantity involved in the lock-unlock statement in the contract needs to be pre-calculated according to the abstract syntax tree, and the result of the calculation will be used to build the transaction, and other statement types such as verify and if-else also need to carry out relevant pre-checking, so as to prevent users from reporting errors when executing the contract.

From the functional level, the front end mainly includes the design of the page, the call of plug-ins, the processing of contract transaction logic, the interaction of buffer server and so on. Next, we will explain these important parts:

1) the design of the front-end page is mainly the design of the web interface, and this part of the developer can choose the page mode by himself.

2) the plug-in wallet has been structurally encapsulated and an external interface is provided for DAPP developers to call. Developers only need to fill in the plug-in parameters according to the rules. For more information, please refer to the DAPP developer Wizard.

3) the contract transaction of the original chain is a multi-input and multi-output transaction structure, and the front end needs to carry out some pre-judgment logic processing, and then select the appropriate contract transaction template structure.

4) the plug-in of DAPP connects to the decentralized bycoin server, which synchronizes all the block information and transaction information from the original node server. This part is highly encapsulated in the plug-in wallet layer, and users only need to call it according to the API. In addition, developers are required to build a buffer server, which can not only do some performance processing at the management contract UTXO level, but also do some data storage for DAPP. Developers can develop some RPC request interfaces according to their actual needs, and then set relevant conditions on the front-end page to trigger these API calls.

The front-end logic processing flow is roughly as follows:

Call the plug-in. The source code of the original chrome plug-in is located in Bytom-JS-SDK. For more information on how to call the plug-in than the original DAPP, please see Dapp Developer Guide. The network configuration is as follows:

Window.addEventListener ('load', async function () {if (typeof window.bytom! = =' undefined') {let networks = {solonet: / / solonet bycoin url testnet:. / / testnet bycoin url mainnet:. / / mainnet bycoin url};. StartApp ();}

You can configure contract parameters by file configuration. This step is to enable the frontend to get some fixed contract parameters that need to be used. The frontend configuration file is configure.json.js. The example model is as follows:

Var config = {"solonet": {. / / contract arguments "gas": 0.4 / / btm fee}, "testnet": {.}, "mainnet": {.}}

The front-end precomputation process, if the contract contains a lock-unlock statement and Amount is a numeric expression, then the front end extracts the evaluation expression and performs the corresponding precomputation. In addition, the front end also needs to prejudge all verifiable verify statements to determine whether the transaction is feasible, because once the front end fails to validate these statements, the contract will inevitably fail. In addition, if the define or assign statements involve variables, the front end also needs to precalculate the values of those variables.

To construct the contract transaction template, because unlocking the contract is the condition of unlocking the lock statement, the construction of the transaction needs to be transformed according to the lock statement or unlock statement. The unlocked contract transaction is composed of inputs and outputs. The first input input of the transaction is generally fixed, that is, the hash value of the contract UTXO. In addition, other inputs and outputs need to be changed according to the actual contract in DAPP. The model is roughly as follows:

Const input = [] input.push (spendUTXOAction (utxohash)). / / other inputconst output = [] output.push (controlProgramAction (amount, asset, program)). / / other output

Start the front end service

Compile the front-end command as follows:

Npm run build

Before starting, you need to start the bufferserver buffer server, and then start the frontend service. The frontend startup command is as follows:

Npm start

DAPP buffer server

The main purpose of the buffer server is to do some efficiency processing at the UTXO level of the management contract, including how to synchronize the request to the bycoin server, and to store the related transaction records of DAPP. The bycoin server is a decentralized wallet server than the original chain, and the UTXO of the buffer server is updated synchronously with it. It is the server that is connected by default than the original official plug-in wallet. Although the bycoin server is also managed compared to all the UTXO of the original chain, due to the large number of UTXO, if you directly deal with it at this level, it will lead to poor DAPP performance, so it is recommended that you build your own buffer server for further optimization. In addition, DAPP developers can also build their own decentralized wallet server and develop their own plug-ins.

The buffer server architecture can refer to the source code of the bufferserver case. The compilation and startup steps are as follows:

Compile the bufferserver source code

Install the packages Mysql and Redis required for the deployment service according to README, then download the source code and compile:

Make all

After the compilation is complete, the executable files api and updater are generated in the target directory.

Start the service

Create a database and data table using the root user with the following command:

Mysql-u root-p < database/dump.sql

Modify the configuration file config_local.json. For configuration instructions, please see the config configuration parameters of README.

Start the api and updater servers, where api is the service process that provides JSON RPC requests and updater is the service process that provides synchronous blockcenter and blockchain browser data requests.

. / target/api config_local.json./target/updater config_local.json

After starting the buffer server, you can start the front-end service, and then open DAPP's web page URL to use.

Attached: the JSON RPC API of the buffer server can refer to the description of the wiki API.

This is the end of "how to start the bytom DAPP buffer server". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report