Mastering Web3 with Waves Module #5

Ventuary Lab
Mastering Web3 with Waves
13 min readJul 7, 2019

Module #5 Tokenisation and Smart Assets

5.1 Tokenization;
5.2 Operations with Assets: Part 1;
5.3 Operations with Assets: Part 2;
5.4 Smart Assets3.5 Smart Accounts and Decentralised Applications (dApps);
5.5 Coupon-Bazaar’s digital assets

What is tokenization?

The first thing we have to discuss is what, exactly, tokenization is. Broadly speaking, tokenization is the process of converting some form of asset into a token that can be moved, recorded, or stored on a blockchain system. That sounds more complex than it is. To put it simply, tokenization converts the value stored in some object — a physical object, like a painting, or an intangible object, like a carbon credit — into a token that can be manipulated along a blockchain system.

https://blockonomi.com/tokenization-blockchain

As we can see The evolution of Money has several important milestones:

  • Barter before money
  • Gold and Silver after
  • Metal Coins
  • Paper Money or Bank Notes
  • Plastic Cards
  • Electronic Money
  • And finally cryptocurrencies and tokens — the modern phenomenon.

So, tokens are just more effective and automated digital forms of assets.

Due to decentralized nature, operations with tokens are fully automated and can’t be moderated or blocked by any single third party. It makes the tokenized systems global and available for everyone on the Earth. No matter what is a country of origin, political situation, culture, religion or economic situation.

To have a monetary value any crypto asset (token) must be liquid.

In business, economics or investment, market liquidity is a market’s feature whereby an individual or firm can easily and quickly purchase or sell an asset without causing a drastic change in the asset’s price.

To have a utility value any token should be designed as a required component of dApps or business operations.

You can also trade tokenized assets with many strategies on exchanges by placing orders to sell or to buy.

Waves DEX — is a decentralized exchange for many liquid tokenized assets.

just like everything in the economy crypto assets has price determined by the equilibrium between demand and supply. More demand — the higher price of an asset. (Note: This may not works with Smart Assets, where you’re able to restrict some options by applying asset script).

We’re already familiar with WAVES — the native token of the waves blockchain public network.

In any public blockchain, a native token is very important for the platform functionality:

  • It makes any DDoS attacks expensive (because of fees)
  • It incentivizes networks nodes/block producers to maintain the network
  • It incentivizes the platform contributors to improve the infrastructure

In this module, we’ll try to make our own tokens and automate some operations with tokens by making them smart.

Let’s call tokens, which aren’t “native” tokens for the public chain, as a “custom tokens”. Any tokens besides WAVES token are custom tokens in the waves blockchain.

There are many things we can do with custom tokens:

* Issue — means that we’re able to create our own tokens

* Re-Issue — means that we’re able to “print” more tokens (if it’s still possible — depends on Issue params) or change their logic by applying asset script

* Burn — means that, in certain circumstances, we’re able to delete some tokens from the circulating supply

* Transfer

* Exchange — we’re able to trade tokens on DEX (decentralized exchange)

* Invokations — our dApps are able to work with custom tokens too

* Set Asset Script — the process to make a smart asset from the custom asset, or change the behavior of existing smart assets

Let’s learn how to work with tokens in our web3 applications!

next…

Everyone is able to issue a new token with certain parameters. To do that in JavaScript just use issue transaction method.

This is the “custom currency” token case.

Look at the parameter — decimals. By setting it as 2 you’ll have the same picture as with EUR and CENT. 1 CENT is a 1/100 of EUR and it’s minimal token value available for operations like transfers, exchanges or burn.

If you set reissuable parameter by false the issued token parameters will never be changed (reissued or became a smart asset).

Documentation: https://docs.wavesplatform.com/en/blockchain/token/custom-tokens.html

API: https://wavesplatform.github.io/waves-transactions/globals.html#issue

P.S.: In Waves Client UI anyone is able to issue a token just by several clicks:

(testnet Waves Client UI: https://testnet.wavesplatform.com/tokens )

! Please, use the ‘default account’ as a signature provider for all challenges in this module to pass them. Otherwise, fees will be different

Try to Issue your own token by using the JS code from “Step 2” (with 2 decimals).

Find this token in the explorer and put here the value of “Scripted” field:

hint: https://wavesexplorer.com/testnet/assets/{asset_id}

! Please, use the ‘default account’ as a signature provider for all challenges in this module to pass them. Otherwise, fees will be different

Try to Issue your own token by using the JS code from “Step 2” (with 2 decimals).

Find this issue tx in the explorer and put here the value of “Fee” field:

hint: https://wavesexplorer.com/testnet/tx/{asset_id}

! Please, use the ‘default account’ as a signature provider for all challenges in this module to pass them. Otherwise, fees will be different

Try to Issue your own token by using the JS code from “Step 2” (with 2 decimals).

Find issuer’s account in the explorer (assets tab) and put here the value of “Balance” field for issued token:

Users are able to issue indivisible tokens by setting decimals to zero.

In our coupon bazaar dApp we’re working with indivisible digital assets — “coupons”.

! Please, use the ‘default account’ as a signature provider for all challenges in this module to pass them. Otherwise, fees will be different

Try to Issue your own indivisible token (quantity — 100) by using the JS code from “Step 6” (with 0 decimals).

Find an issuer’s account in the explorer (assets tab) and put here the value of “Balance” field for issued indivisible token:

Re-Issue — means that we’re able to “print” more tokens (if it’s still possible — depends on Issue params) or change their logic by applying asset script

Supplier may wish to sell a bit more coupons for the same service or product on the marketplace.

! Please, use the ‘default account’ as a signature provider for all challenges in this module to pass them. Otherwise, fees will be different

Try to Issue your own indivisible token (quantity — 100) by using the JS code from “Step 6” (with 0 decimals). Reissue 10 more tokens (“Step 8”).

Find reissue tx in the explorer and put here the value of “Fee” field:

In Waves Client UI anyone is able to transfer a token from one address to another.

Testnet Waves Client UI: https://testnet.wavesplatform.com/wallet/portfolio

Let’s do that in UI first and in JavaScript later.

Find your coupon token in the portfolio and try to send a new token to another address.

! Please, use the ‘default account’ as a signature provider for all challenges in this module to pass them. Otherwise, fees will be different

Try to send a coupon token in testnet client UI:

Find transfer tx in the explorer and put here the value of “Fee” field:

! Please, use the ‘default account’ as a signature provider for all challenges in this module to pass them. Otherwise, fees will be different

Which api (@waves-transactions) function is using for assets transfers?

Exchange — we’re able to trade tokens on DEX (decentralized exchange)

Let’s do that manually on testnet DEX:

The issuer is able to sell his tokens by placing an order — “Sell”. Other users are placing “Buy” orders.

So, we have an order book for our token.

When prices for “Sell” and “Buy” orders are the same, we have a match and orders execution — i.e. Exchange Transaction.

API: https://wavesplatform.github.io/waves-transactions/globals.html#exchange

! Please, use the ‘default account’ as a signature provider for all challenges in this module to pass them. Otherwise, fees will be different

Try to exchange some coupon tokens in testnet DEX (from one account to another):

Use “coupon / WAVES” pairs.

Find exchange tx in the explorer and put here the value of “Fee” field:

Page with the Waves Client UI link: https://stepik.org/lesson/237607/step/2?unit=209936

! Please, use the ‘default account’ as a signature provider for all challenges in this module to pass them. Otherwise, fees will be different

Users are able to Burn their tokens.

For example: In our case — suppliers may wish to burn coupon tokens when coupons have transferred back from customers.

API: https://wavesplatform.github.io/waves-transactions/globals.html#burn

Let’s burn 10 tokens:

Find burn tx in the explorer and put here “Fee” field value:

In previous modules, we’ve seen how dApps might work with WAVES — native token.

To let them work with custom tokens we must apply some logic to the @Callable functions.

Let’s look at the “Multi-user wallet” example which is working now only with wEUR currency (token):

i.payment.assetId — must be used to allow or deny dApp’s transactions.

ScriptTransfer is using the proper assetId to execute transfer funds from dApp’s account to certain addresses.

The same logic in JavaScript code. Just use your asset id in the payment parameter of invokeScript tx.

next…

Try to implement a new wallet dapp (“Step 1”) with your token support and deploy the account script.

Find this account script in the explorer and put the decompiled code here:

Try to implement a new wallet dapp (“Step 1”) with your token and deploy the account script.

Deposit 3 wEUR tokens to the dApp.

Find the deposit invoke tx in the explorer and put the “Payment” field value here:

A non-fungible token (NFT) is a special type of cryptographic token which represents something unique; non-fungible tokens are thus not interchangeable. This is in contrast to cryptocurrencies like bitcoin, and many network or utility tokens that are fungible in nature.

https://en.wikipedia.org/wiki/Non-fungible_token

Non-fungible tokens are used to create verifiable digital scarcity. NFTs are used in several specific applications that require unique digital items like crypto-collectibles and crypto-gaming, certificates or unique coupons.

In Waves, NFTs are custom tokens with 0 decimal and 1 quantity.

The issue fee for NFTs are 1000x less than for Non-NFTs.

Users can’t send a piece of those tokens.

Traditional contracts represent agreements between participants (parties), these agreements are validated and enforced by some third-party official entity or government. Third-party entities are key participants for validation of contract’s conditions, environmental circumstances, and events which could influence the contact’s agreement execution.

Despite similar terms, smart contracts aren’t contracts by definition of “agreement between parties”. The smart contract is a computer source code or program which can be executed within a distributed environment like blockchain network. All operations and execution results are stored in the blockchain.

In this definition, a smart contract is not a contract between parties, but it’s a protocol of cooperation between users, and also between user and computer or even computer and computer according to rules described in the smart contract source code.

In Waves, we have two types of smart contracts: Smart Accounts (dApps) and Smart Assets.

Smart Asset script allows or denies some outgoing transactions with certain assets, depending on some conditions, described within the smart asset script code.

Let’s look at the great working example of smart assets: Waves Reward Tokens (WRTs).

The goal: Only ambassadors will be able to sell WRT, which Waves team will buy back on DEX. It’s a special case of loyalty and motivation programs.

Waves Community members who satisfied at certain conditions are receiving some amount of WRTs (monthly or quarterly basis).

They will subsequently be able to send WRT to Waves ambassadors as a reward for their activities.

By introducing WRT, Waves team encourages the community to keep track of ambassadors’ activities, expressing opinions and rewarding them, if they deserve it.

The smart asset will operate as follows:

  • WRT can only be sent to whitelisted addresses (those of ambassadors)
  • The token cannot be burnt
  • It cannot be traded on DEX; only whitelisted addresses can sell it

The mainnet WRT token id: H1RmwqzeXsdQMt6jR6DPkGbZjA2PKUoofP4WjuCRz1st

Find WRT token in the mainnet waves explorer and put here the smart assets decompiled script:

Find WRT token in the mainnet waves explorer and read the smart assets decompiled script.

Find the key-value storage with the whitelist and put all key-value data here:

Try to make your own Smart Asset by applying the script to your issued token (choose any form created in this module or create a new one).

In this Smart Asset script, only exchange transactions are allowed for everyone.

API: https://wavesplatform.github.io/waves-transactions/globals.html#setassetscript

StackOverflow: https://stackoverflow.com/questions/55041411/how-to-set-a-script-for-an-asset-using-waves-ide

Hint: IDE’s library with Smart Assets cases

Put your RIDE smart asset code here:

This is a continuation of the previous step…

Try to make your own Smart Asset by applying the script to your issued token (choose any form created in this module or create a new one).

In this Smart Asset script, only exchange transactions are allowed for everyone.

API: https://wavesplatform.github.io/waves-transactions/globals.html#setassetscript

StackOverflow: https://stackoverflow.com/questions/55041411/how-to-set-a-script-for-an-asset-using-waves-ide

Put your Java Script test code here:

Users are searching for goods and services discounts and they can buy them for a small price in the marketplace.

Each coupon — is a digital asset which represents a special discount from the supplier.

“Coupon Bazaar” is a marketplace of digital assets — tokenized coupons provided by suppliers.

Suppliers are able to configure some logic for those coupon tokens like quantity and expiration.

We already have a Coupon Bazaar dApp smart contract and test functions. Let’s add some functionality for a supplier:

1. Suppliers:

• Add an Item => Issue tokens / Re-Issue + Set Asset Script
• Withdraw funds
• Accept tokens from customer and burn tokens

2. Costumer:

  • Buy tokenized coupon
  • Transfer tokens to the usersTrade tokens on DEX

In the RIDE smart asset code, we allow burning and reissuing coupons only for the supplier who is the issuer.

Customers are able to purchase coupons, sell coupons on the DEX, transfer coupons to the friends and family members within the expiration period.

P.S.: look at the trick in the IDE. You can use the file(…) function to use the RIDE source code text.

Let’s create your own “coupon” smart asset! Find the assets script in the explorer and put decompiled code here:

Actually, we have everything now to build our own fully functional coupon bazaar web3 dApp.

In Module 6 we’ll combine all together!

--

--

Ventuary Lab
Mastering Web3 with Waves

DLT, Web3.0, Blockchain, Decentralization, Startups, Waves Platform