DAPP network usage strategy: how to use Zeus and vRAM
LiquidApps
2019-08-24 05:13
本文约5942字,阅读全文需要约24分钟
This article is the first of the DAPP network series interpretation, introducing the Zeus SDK development kit, which is used to support developers in rapid dApp development, testing and deployment, and integrates many DAPP network services. Follow this C

If you're reading this, you've probably heardDAPP network, the DAPP Network providesvRAMand other types of services to help developers create a new generation of scalable, easy-to-use dApps.

In the DAPP network use strategy series starting from this article, under our guidance, you can use the services of the DAPP network in dApps to add many powerful functions to your application. Before the emergence of the DAPP network, these functions were previously Not available in a decentralized manner.

Developers can choose service packages provided by DAPP service providers (referred to as DSPs) in the free market of the DAPP network. For the convenience of developers, LiquidApps also providesZeus SDKA development kit that makes it easier for your dApp to use services on the DAPP network.

The DAPP network is currently deployed on the EOS mainnet, and at the time of writing, there are 13 different DSPs offering a total of 34 service packages, most of which are vRAM type services.

A large number of services are provided in the DAPP network. In order to make it easier for developers to understand, we have written this series of articles to explain how to use the rich and diverse functions provided by the DAPP network: for example, network and cross-chain oracle services (LiquidOracles),CRON job scheduling service (LiquidScheduler),Random number generation, virtual account (LiquidAccounts), and the vRAM service (https://liquidapps.io/vRam) wait.

In order to better use these services, we need to understand how to use the basic tools: how to useZeus SDK

Zeus SDKIt is an easy-to-use and highly extensible development framework that allows dApp developers to use the products and functions of the DAPP network by adding a minimum amount of smart contract code.

secondary title

Setting up and using NVM

If you have already configured NVM, this part can be skipped.

NVM is the Node version manager used for development version management of Node.js. If you haven't installed it yet, it is recommended that you install and configure the software first. NVM can help you use and switch node versions very conveniently.

Note: It is not recommended to use Homebrew install to install NVM on Mac.

If you are developing on MacOS, you may be prompted to install the Xcode command-line tools in the following steps.

secondary title

$ nvm install 10.x
$ nvm use 10.x
$ nvm install-latest-npm

Install Zeus dependencies on Linux

On Linux, you may need to install some dependencies:

Ubuntu/Debian:

$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test$ sudo apt update
$ sudo apt upgrade -y libstdc++6
$ sudo apt install -y make cmake build-essential python

Centos/Fedora/AWS Linux:

$ sudo yum install -y make cmake3 python git gcc-c++ wget
$ export CMAKE_PREFIX_PATH=/usr/opt/eosio.cdt/1.6.1/lib/cmake/eosio.cdt

secondary title

$ wget https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gz
$ tar xvfx cmake-3.14.3.tar.gz$ cd cmake-3.14.3
$ ./bootstrap
$ gmake
$ sudo make install
$ cd ..

Install and deploy Zeus

When installing Zeus, if you use the -g flag, it will be installed globally:

$ npm install -g @liquidapps/zeus-cmd

However, even if Zeus is installed globally, onlyzeus unboxCommands can be used globally.

andzeus testzeus migrateandzeus compileThe commands of the class belong to the extended type and will only be passed in thezeus unboxThese commands will only take effect in the unpacked folder obtained by the command.

After Zeus is installed, you can unpack the Helloworld contract for testing to make sure everything works.

Create or select a folder to store after unpacking, and then run the following command:

**$** zeus unbox helloworld
**$** cd helloworld
**$** zeus test

implementzeus unboxThe operation will create many files and folders in the helloworld folder, and generatezeus-box.jsondocument.

The Zeus SDK comes with many other examples, which can be viewed with the following command:

zeus list-boxes

anddeepfreeze, vgrab, cardgame,andregistryWait, it also includesmicroauctions, eos-detective-reports(EOS Detective Report),token(created to deploy the standard eosio.token contract) and many more examples.

for displayAdd service typesecondary title

Add vRAM to smart contracts

Now that the Zeus SDK is set up, it can be used for our EOSIO development work.

First, let's look at how to add thevRAM

For reference, you can also get the full code of the complete War of the Elements tutorial, this version provided by BlockOne, does not include vRAM:https://github.com/EOSIO/eosio-card-game-repo/tree/lesson-8

Run the zeus unbox cardgame command to get the vRAM version of the War of the Elements code.

Please note: due to network reasons, it may take a long time for Chinese users to use the zeus unbox command to obtain relevant codes, please wait patiently

assuming you are stillhelloworldIn the folder:

cd ../
$ zeus unbox cardgame
$ cd cardgame

zeus unboxThe last part of the output provides some useful guidance on what to do next:

(OUTPUT)
Enter new directory:
 cd cardgame
Please try these sample commands:
 ⭐Deploy contract: zeus migrate
 ⭐Run frontend locally: zeus run frontend main
 ⭐Build frontend: zeus build frontend main
 ⭐Deploy frontend: zeus deploy frontend main
 ⭐Deploy and register frontend: zeus deploy frontend main — ipfs — register cardgame1111

To explain the above:

(OUTPUT) Enter a new folder name: cd cardgame Try the following example commands: ⭐Deploy contract: zeus migrate ⭐Run frontend function locally: zeus run frontend main ⭐Create frontend: zeus build frontend main ⭐Deploy frontend: zeus deploy frontend main ⭐Deploy and register frontend: zeus deploy frontend main — ipfs — register cardgame1111

secondary title

$ zeus migrate && zeus run frontend main

How to enable vRAM for a contract

To understand how to convert this contract to a vRAM-enabled contract, first look atcardgame.hppthis document.

orcardgame.cpporgameplay.cppThe file doesn't even have to be changed, just thecardgame.hppThe code in the file will do.

Please note: The cardgame contract after decompression may containsome extra features, we didn't mention it in this tutorial, don't worry, it will be introduced in the following strategy.

$ cd cardgame/contracts/eos/cardgame
$ nano cardgame.hpp

In the file, we can see that adding vRAM follows a number of simple steps. Some side notes if you are not aware of some of the recent changes to EOS CDT.

1) First, use the standard#include way to import the EOSIO header files, then we see the libraries needed to import the vRAM DAPP service, and a number of new preprocessor directives:

Note: In versions prior to CDT 1.7 and in the original War of the Elements code, the first line of code was not#include but#include ,but,#include This method has been deprecated.

#include "../dappservices/multi_index.hpp"
#define DAPPSERVICES_ACTIONS() \
 XSIGNAL_DAPPSERVICE_ACTION \
 IPFS_DAPPSERVICE_ACTIONS
#define DAPPSERVICE_ACTIONS_COMMANDS() \
 IPFS_SVC_COMMANDS() 
#define CONTRACT_NAME() cardgame

If we need other services, we can import them here. For example, if this contract also requiresOracle Oracle Service

·/* ORACLES EXAMPLE ONLY NOT FOR VRAM */

#include "../dappservices/multi_index.hpp"

#include "../dappservices/oracle.hpp"

#define DAPPSERVICES_ACTIONS() \
 XSIGNAL_DAPPSERVICE_ACTION \
 IPFS_DAPPSERVICE_ACTIONS \
 ORACLE_DAPPSERVICE_ACTIONS

#define DAPPSERVICE_ACTIONS_COMMANDS() \
 IPFS_SVC_COMMANDS() \
 ORACLE_SVC_COMMANDS()

#define CONTRACT_NAME() cardgame

We'll cover how to use services other than vRAM in a follow-up article.

2) After all our instructions (including using statements), we tell Zeus that our contract can start:

CONTRACT_START()

3) We modified the type of the "users" data table and changed its type definition (typedef) to dapp::multi_index type. In the original code, the type of the data table is eosio::multi_index. We replaced it with dapp::multi_index to enable the vRAM service for the users table. This is a table used by the contract for many references to its unique table users_table _users.

Note: The expression of name("users") is equivalent to "users"_n.

typedef dapp::multi_index users_table;

4) To support client queries, a new ".users" table was added using the same user_info structure, and a "users" table now defined by the shardbucket structure:

typedef eosio::multi_index<".users"_n, user_info> users_table_v_abi;

TABLE shardbucket {
 std::vector shard_uri;
 uint64_t shard;
 uint64_t primary_key() const { return shard; }
};

typedef eosio::multi_index<"users"_n, shardbucket> users_table_abi;

Note: In the code for the original War of the Elements sample program, thestruct[[eosio::table]]replaceTABLE. These expressions are equivalent;TABLEis a macro that can be translated by the compiler tostruct[[eosio::table]]

5) Finally, at the end of the file we have theEOSIO_DISPATCHThe macro is slightly modified,
Here, CONTRACT_END() is used to indicate the end of the contract, corresponding to the CONTRACT_START() we wrote earlier at the beginning of the file:

CONTRACT_END((login)(startgame)(playcard)(nextround)(endgame))

Zeus can now compile our smart contract into a vRAM enabled dApp. Note that secondary indexes for use on vRAM are currently not supported.

As before, we can now deploy our contract to the local test network and use the local DSP to provide services for testing:

 zeus migrate && zeus run frontend main

For more information, see the ever-improvingLiquidApps Documentation,, if you have any questions, please join ourTelegram Developer Channel

In the next article, we will introduce how to deploy the vRAM version of dApp on the Kirin testnet, how to mortgage DAPP tokens to DAPP service providers to use vRAM services, and how to deploy applications on the EOS mainnet.

Follow LiquidApps Developers on twitterFollow the rest of the series to learn how to effectively use the full suite of services offered by the DAPP Network.

You can also scan the QR code at the end of the article, add the community manager WeChat, invite you to join the LiquidApps Chinese developer community, get the latest information, and discuss with many developers how to use DAPP network services to create a new generation of dApps.


Welcome to the LiquidApps community

The mission of LiquidApps is to reduce the difficulty and cost of blockchain development by introducing a series of technical solutions, so as to promote the large-scale development and implementation of decentralized applications (dApps).

Official website:

Official website:https://www.liquidapps.io/

Bihu:https://bihu.com/people/1528429636

Twitter:https://twitter.com/liquid_dapps

English telegram group:https://t.me/LiquidAppsOfficial

Weibo:https://t.me/LiquidApps_community_China

Weibo:https://www.weibo.com/7126862764/profile?topnav=1&wvr=6&is_all=1

For WeChat group, please scan the QR code to add LiquidApps China Community Manager to join the group.

LiquidApps
作者文库