Playing with IOTA: Parsing Data For Supply chain project

Yehia Tarek
Coinmonks
4 min readOct 1, 2019

--

Hello Everyone, I am new at IOTA development and I decided to make a supply chain system using IOTA the project will force organizations to use Eco-Friendly material by giving rate for each organization of how much they consume the Eco-Friendly materials and keep tracking the product till we get it back for recycling. If you aren’t familiar with IOTA I recommend you read the documentation and you should know Nodejs basics.

While designing my project idea I made a simple prototype for establishing a secure connection to track all products.

What I will do?

1-Create a customized ID refer to Eco-Friendly materials producer, The Buyer and the order of the product( example: first created product, second created product..etc)

2-This ID will be like a bar-code on each product.

3-Each time the bar-code reader detected a product. It will send a JSON Object with the product ID, current bar-code reader ID and the current time. So I could track a large number of products.

How My prototype establishes communication?

1-Send a restricted MAM message with content ‘Initialize Root’ and return the root address.

2-Send all Products as a JSON object using restricted MAM.

3-Send the root address as a public transaction.

4- Fetch root address From public transaction.

5-Parse it to all devices with the side key to fetch all Products JSON objects.

Code Implementation:

First, we need to install the iota packages

OR

you could use yarn add

Now, create your JavaScript file touch SendPublicTransaction

Import Packages and connect it to the blockchain.

To send public data, I assume you are familiar with seeds and addresses if note check this link. We need to create a transfer object with the address destination and the message content and for sure the transmitted value on our case will be zero.

To fetch this message :

If you are facing difficulties in understanding this code check this video created from the IOTA foundation explaining it in detail. I added some promises if you don’t know what is it to check this link.

Then we have the restricted MAM code

Initialize MAM

Send a MAM message

Send more then one Message using foreach

fetch all Restricted MAM messages:

And that it now all you need to do is to connect all code.

sendID.js File:

fetchID.js File:

Find all code on my Github link: https://github.com/yehia67/Products-Tracker-Prototype/

If you have any question please ask me. Thank you!

Get Best Software Deals Directly In Your Inbox

--

--