Playing with IOTA: Parsing Data For Supply chain project
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 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 establish the communication?
1-Send a restricted MAM message with content ‘Initialize Root’ and return the root address.
2-Send all Products as a JSON objects 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
npm install @iota/core
npm install @iota/converter
OR
you could use yarn add
Now, create your JavaScript file touch SendPublicTransaction
Import Packages and connect it to the blockchain.
const iotaLibrary = require(‘@iota/core’)
const Converter = require(‘@iota/converter’)
const iota = iotaLibrary.composeAPI({
provider: ‘https://nodes.devnet.thetangle.org:443'
})
To send public data, I assume you are familiar with seeds and addresses if note check this link. We need to create transfer object with the address destination and the message content and for sure the transmitted value on our case it will be zero.