LiquidApps Walkthrough #2: Staking to DAPP Service Providers and Deploying a vRAM dApp

Learn how to deploy a dApp with scalable storage on the Kylin testnet

DAPP Network
The DAPP Network Blog
8 min readSep 10, 2019

--

In walkthrough #1, we looked at what it takes to enable vRAM, a decentralized and scalable storage solution, in a smart contract.

But in order to use vRAM and the many other LiquidServices on a public network, we need to subscribe to packages offered by DAPP Service Providers (DSPs) by staking the appropriate amount of DAPP tokens to those DSPs.

In the case of vRAM, the package we’re looking for is ipfsservice1. On the mainnet, we’re in luck with this service: as of September 7, 49 of the 70 available DSP packages are ipfsservice1.

You can view this information on one of the available community DSP Portals. This one is dsphq.io.

We won’t be deploying on mainnet in this walkthrough. However, the testnet deployment we follow will be roughly the same process as mainnet deployment.

In order to deploy a vRAM-enabled dApp on Kylin testnet, we’ll need to get an account set up and get it some testnet EOS so it can afford the resources it needs to deploy the contract.

Note that the account will still need some RAM in order to deploy, as contracts are held in RAM and cannot be held in vRAM. vRAM generally reduces an application’s RAM requirements, but it does not eliminate them.

So let’s set up our Kylin testnet account.

Note: if you’re more into documentation than walkthroughs and just want a list of commands, head to the LiquidApps docs page for Kylin setup.

You can go to https://www.cryptokylin.io to find out more about it, but it’s easy to create an account. To make our account for this tutorial, 1111dsptutor, we just visit this URL:

http://faucet-kylin.blockzone.net/create/1111dsptutor (You’ll have to choose your own account name instead of 1111dsptutor, since as of a few seconds ago, 1111dsptutor is now taken.)

Save the information you receive! The page will provide you two different keypairs with owner and active permissions for your new Kylin account.

Note: if you receive 404 or other errors while trying to access the faucet, they are likely temporary. Try again in a little while, or ask for help creating a Kylin account in the CryptoKylin English Telegram channel.

Getting some EOS for our testnet account is just as easy: http://faucet-kylin.blockzone.net/get_token/1111dsptutor

Now our Kylin account has 100 EOS.

(Optional) Let’s add our new Kylin account to Scatter.

Click the little gear in the top right of the Scatter window.

Now select “Networks” from the settings menu. It’s in the “danger zone,” so you’ll have to enter your password.

1) Under “Your Networks,” enter the following information (or look up information for a different Kylin endpoint here):

Name: Kylin testnet
Host: 178.62.36.41
Port: 8888
Protocol: http
Chain ID: 5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191

Click “Add,” and you’re done adding the testnet network.

2) Now, import the private keys you obtained into Scatter.

3) You will likely need to manually “link accounts” (in my case, I’d enter 1111dsptutor@active and 1111dsptutor@owner) since Kylin is a network that Scatter doesn’t include by default.

Now we can check out our account on the Kylin Block Explorer at https://kylin.eosx.io

Sweet! Now we too can print money like the Fed. (There’s a reason testnet EOS is worthless.)

We can also see that we have 9.5 kB of RAM. We’ll need more to deploy and test our contract — we can do this at https://kylin.bloks.io with our new Scatter setup. Since we don’t know how much RAM we’ll need yet, we’ll postpone buying RAM for now.

(Optional) Time to set up cleos if you haven’t yet.

Remember that in order to use cleos options when we buy RAM, register packages, and deploy contracts, you’ll need to import this key into your cleos wallet with cleos wallet import. In case you haven’t set up a cleos wallet locally, follow steps 1 through 3 of the instructions at the EOSIO Developer Portal to do so

Now, let’s check out the vRAM packages available on the Kylin DSPs.

The DSP Portals allow you to view Kylin testnet DSPs, as well. For example, DSP HQ (shown earlier) has a toggle in the top right which brings you to dsphq.io/?network=kylin and back.

Another DSP Portal, Bloks.io, has its Kylin portal is at kylin.bloks.io/dsp:

We need to see only vRAM packages. Others services such as LiquidOracles (oracleservic), LiquidScheduler (cronservices), and more also have packages available.

The vRAM packages available have various stake amounts, minimum unstaking periods (usually 1 hour), package quotas, and package periods. I’m going to pick an ipfsservice1 package, “package1”, from the DSP “heliosselene”, although “uuddlrlrbass” might appeal more to those of you who are more … Contra-rian. (Ba-dum ts).

We’ll stake the 10 DAPP specified in min_stake_quantity and see how that works for us.

To get some Kylin DAPP, go to kylin-dapp-faucet.liquidapps.io.

Enter your account (in my case “1111dsptutor”) and you’ll get 1000 Kylin DAPP! There’s no confirmation here, though you’ll probably get hit with a captcha challenge, but you can see the transaction over at your account’s page at https://kylin.eosx.io or another explorer.

Now that we have some DAPP, let’s select a package and stake some to it.

Substitute your chosen Kylin endpoint (if different), your DSP and your DSP package, and your account name as needed.

You’ll need to be in the folder where we unboxed the cardgame contract in walkthrough #1.

If using cleos,

1. First, let’s set some variables to make the process easier.

Note: if you receive 404 or other errors while trying to access the faucet, they are likely temporary. Try again in a little while, or ask for help creating a Kylin account in the CryptoKylin English Telegram channel.

Replace 1111dsptutor with your username:

$ export KYLIN_TEST_ACCOUNT=1111dsptutor$ export KYLIN_TEST_PUBLIC_KEY=EOS52EvB8SfrxFGmq3cSeMHiAXpjyaBQkgX28A5pxtr8ETXkJT2Ss$ export $EOS_ENDPOINT=https://kylin-dsp-2.liquidapps.io

Note: in the future, you can streamline the earlier steps we did above in a browser right here in the terminal instead, as follows:

# Create a new available account name (replace '1111dsptutor' with your account name):
export ACCOUNT=1111dsptutor

# Configure endpoint
export DSP_ENDPOINT=https://kylin-dsp-1.liquidapps.io

# Create wallet
cleos wallet create --file wallet_password.pwd

# Create account and import key
curl http://faucet-kylin.blockzone.net/create/$ACCOUNT > keys.json
export ACTIVE_PRIVATE_KEY=`cat keys.json | jq -e '.keys.active_key.private'`
export ACTIVE_PUBLIC_KEY=`cat keys.json | jq -e '.keys.active_key.public'`
cleos wallet import --private-key $ACTIVE_PRIVATE_KEY
# if this does not work, import key directly

# Get some tokens, stake CPU/NET, buy RAM for contract
curl http://faucet-kylin.blockzone.net/get_token/$ACCOUNT
curl http://faucet-kylin.blockzone.net/get_token/$ACCOUNT
cleos -u $DSP_ENDPOINT system buyram $ACCOUNT $ACCOUNT "100.0000 EOS" -p $ACCOUNT@active
cleos -u $DSP_ENDPOINT system delegatebw $ACCOUNT $ACCOUNT "20.0000 EOS" "80.0000 EOS" -p $ACCOUNT@active

You can use the final two commands again to get more Kylin EOS and increase the CPU and Net resources for the current test account if needed. Visit https://kylin-dapp-faucet.liquidapps.io to get more Kylin DAPP, as we did earlier.

2. Select a package.

$ cleos -u $EOS_ENDPOINT push action dappservices selectpkg "{\"owner\":\"$KYLIN_TEST_ACCOUNT\",\"provider\":\"heliosselene\",\"service\":\"ipfsservice1\",\"package\":\"package1\"}" -p $KYLIN_TEST_ACCOUNT@active

Side note: if we weren’t using a variable for $KYLIN_TEST_ACCOUNT, we could send the data this way:
'['1111dsptutor','heliosselene','ipfsservice1','package1']'
However, doing this with $KYLIN_TEST_ACCOUNT would send those literal characters as data, so we need to use double quotation marks for our data. This, in turn, means we need to use the crowded escape notation of \" for the internal quotation marks around each key and each value.

3. Stake some DAPP.

$ cleos -u $EOS_ENDPOINT push action dappservices stake "{\"from\":\"$KYLIN_TEST_ACCOUNT\",\"provider\":\"heliosselene\",\"service\":\"ipfsservice1\",\"quantity\":\"10.0000 DAPP\"}" -p $KYLIN_TEST_ACCOUNT@active

Alright. This gives us some bandwidth on the IPFS (vRAM) service provided by heloisselene.

It’s time to deploy our dApp contract.

Let’s give it a try so we can see how much RAM we’ll need to deploy.

We’ll proceed using cleos for the rest of the article, but if you chose to use Scatter and a web tool such as bloks.io, all of these actions can be performed there, as well.

1) In order to set our code as a smart contract code, we need to run set contract:

$ cleos -u $EOS_ENDPOINT set contract $KYLIN_TEST_ACCOUNT ./contracts/eos/cardgame -p $KYLIN_TEST_ACCOUNT@active

But instead of deploying, the result tells us how much RAM we need:

So let’s buy enough RAM — in fact, let’s buy more than enough. This is Kylin, after all. RAM is free:

$ cleos -u $EOS_ENDPOINT system buyram $KYLIN_TEST_ACCOUNT $KYLIN_TEST_ACCOUNT "50.0000 EOS" -p $KYLIN_TEST_ACCOUNT@active

2) Now we run our set contract action again, and our vRAM-enabled contract is deployed:

$ cleos -u $EOS_ENDPOINT set contract $KYLIN_TEST_ACCOUNT ./contracts/eos/cardgame -p $KYLIN_TEST_ACCOUNT@active

Result:

3) Finally, let’s set our contract’s eosio.code permission to finish up this step:

$ cleos -u $EOS_ENDPOINT set account permission $KYLIN_TEST_ACCOUNT active "{\"threshold\":1,\"keys\":[{\"weight\":1,\"key\":\"$KYLIN_TEST_PUBLIC_KEY\"}],\"accounts\":[{\"permission\":{\"actor\":\"$KYLIN_TEST_ACCOUNT\",\"permission\":\"eosio.code\"},\"weight\":1}]}" owner -p $KYLIN_TEST_ACCOUNT@active

Result:

Now we can test our testnet contract!

Remember that, in the unlikely event you run into resource errors, you can stake more Kylin EOS for resources, for example:

cleos -u $EOS_ENDPOINT system delegatebw $KYLIN_TEST_ACCOUNT $KYLIN_TEST_ACCOUNT "250.0 EOS" "200.0 EOS" -p $KYLIN_TEST_ACCOUNT@active

We won’t write comprehensive tests here, but we can at least get started with a simple cleos push action to login.

Replace 1111dsptutor with your desired username here. If you wish, it can be a different Kylin account besides the one that deployed the contract.

$ cleos -u $EOS_ENDPOINT push action 1111dsptutor login '['1111dsptutor']' -p 1111dsptutor@active

It works! If you’d like to try some other cardgame actions, here are some more examples:

cleos -u $EOS_ENDPOINT push action $KYLIN_TEST_ACCOUNT startgame '['1111dsptutor']' -p 1111dsptutor@activecleos -u $EOS_ENDPOINT push action $KYLIN_TEST_ACCOUNT playcard '['1111dsptutor','2']' -p 1111dsptutor@active

In the next part of this walkthrough series, we’ll take a look at the powerful LiquidOracles service and add it to a smart contract.

For more information, please visit the growing LiquidApps documentation page, and if you have any questions, please ask in our Telegram channel or our developers Telegram channel.

Follow LiquidApps

Website | Twitter | Telegram | LinkedIn | Github

Please click here to read an important disclaimer.

--

--

DAPP Network
The DAPP Network Blog

DAPP Network aims to optimize development on the blockchain by equipping developers with a range of products for building and scaling dApps.