What are blockchain mosaics and how they can be implemented on Internet of Things

catapult dragon update

Lesson 1 in NEM: Mosaics Transaction

One of the key features in NEM blockchain is that you can represent an object with a digital asset, known as a mosaic. Each mosaic has a unique ID and cannot be duplicated, using mosaics, we can use it to represent concert tickets, land property, etc.

A mosaic could be a token, but it could also be a collection of more specialized assets such as reward points, shares of stock, signatures, status flags, votes or even other currencies.

The story so far…

From my previous post, we have learned how to build our own private chain on our localhost using the NEM Catapult Cow Version.  In this post, I am going to introduce how to do a transaction (and what that means) on public chains, and how this can be applied with a real use-case I have developed myself. 

Picking up where we left off.

1

We managed to run our own private chain, but what do we do with it? Let’s try to do a mosaic transaction, meaning transferring digital assets from one account to another but first, let’s try doing this on a public-chain instead as the private chain version is already made in this blog. But before you proceed to that website finish the getting started part first as the libraries have a bit of issue.

Getting started

You need to install nodejs on your pc, head to https://nodejs.org/en/ to get the .exe installer.

In order to communicate with our private-chain, install the following dependencies on your PC.

npm install --global nem2-cli

We are using cow version because it is the stable version in the Catapult releases.

Private-keys are DANGEROUS!

Never give your private-keys to anyone, they are basically like your password to access your blockchain account, private keys are generated using an algorithm called SHA3-256, which creates a 256 character hex string, the cool thing about this is that the process is almost irreversible. Meaning its almost hard to guess how your password is in normal text form. Let’s start by generating your own private key here.

Untitled.png

Execute the following and paste in the private key you generated. Make sure your node URL is using http://40.90.163.184:3000

nem2-cli profile create 
Introduce network type (MIJIN_TEST, MIJIN, MAIN_NET, TEST_NET): MIJIN_TEST
Introduce your private key: 76************************************************************FF
Introduce NEM 2 Node URL. (Example: http://localhost:3000): http://40.90.163.184:3000
Insert profile name (blank means default and it could overwrite the previous profile): Hank Bot

Output:

Profile stored correctly
test bot->
Network: MIJIN_TEST
Url: http://40.90.163.184:3000
Address: *************************************
PublicKey: *************************************
PrivateKey: *************************************

Save this somewhere offline (put it in a .txt file and print it out or anything)

Love them Mosaics

The account you generated does not have any mosaics in your inventory, so let’s request some free ones by heading over to https://nf-catapult-testnet.herokuapp.com/.

Untitled.png

Insert your address you created from your terminal (it should start with an S) and request for 10 amounts of mosaics, hit the “CLAIM!” button.

Now go back to your terminal and execute the following bash:

nem2-cli account info --profile "<accountname>"

untitled-3-e1562298180417.png

You will notice a “no resource exists with id ‘<address'” at first, that is because the MIJIN TESTNET is still processing the transaction. Accounts which did not do any transactions before are not registered on the blockchain, resulting nem2-cli unable to track the records (there wasn’t any to begin with).

Transaction time!

Repeat the section “Private keys are dangerous” section, as you need two accounts for this, but this time the other account doesn’t need to beg for mosaics from the testnet.

Execute this in the terminal:

nem2-cli transaction transfer --profile <sender>  --recipient <address> --mosaics <mosaicId>::1

To check whether your other account has received it:

nem2-cli account info --profile  "<accountname>"

An Internet of Things solution

Now we have a basis of how that works, I would like to share out my project of using NEM mosaics as a potential solution to encrypt and log IoT data, providing the next level of security.

This project is made to demonstrate how mosaics can be used as a ticket for RFID tags, so whenever a customer uses an RFID tag, his blockchain account does a mosaic transfer to the main account, meaning he has used up a ticket, if he has many more mosaics, he is still allowed to scan the card until all of his mosaics are depleted.

How does it work?

Picture1.png

So whenever someone uses an RFID card to scan, the information is encrypted using LoRa protocols, then sent via radio wave (915Mhz) to a receiver, the receiver extracts the info, and ask for the password, the info and the password(salt) are combined and hashed using SHA256, this is used as a private key to transfer a mosaic to an address on MIJIN test net on http://40.90.163.184:8000/#/blocks/0.

The code for this project can be found at https://github.com/HankRobot/LoRaBlockchain

Possible Improvements & Developments

Let’s see what further developments we can come up with using the features of mosaics:

Each mosaic has a unique identifier and a set of configurable properties. During the mosaic creation, you can define:

Property Type Description
Divisibility Integer Determines up to what decimal place the mosaic can be divided. Divisibility of 3 means that a mosaic can be divided into smallest parts of 0.001 mosaics. The divisibility must be in the range of 0 and 6.
Duration Integer Specifies the number of confirmed blocks the mosaic is rented for. Duration is allowed to lie up to 3650 days (10 years). To create non-expiring mosaics, leave this property undefined.
Initial supply Integer Indicates the amount of mosaic in circulation. The total supply must be in the range of 0 and 9,000,000,000,000,000atomic units (absolute amount).
Supply mutable Boolean If set to true, the mosaic supply can change at a later point. Otherwise, the mosaic supply remains immutable.
Transferability Boolean If set to true, the mosaic can be transferred between arbitrary accounts. Otherwise, the mosaic can be only transferred back to the mosaic creator.

One of the key features of mosaics that really caught my eye is the duration and transferability, this way we can avoid ticket reselling issues and set up a deadline for customers for transactions to access certain services such as the RFID access.

My next project will focus on multisignature transaction, stay tuned!

Advertisements

One Comment Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s