This Reactor Extension script is part of EVRYTHNG's Blockchain Integration Hub. It can be used to send EVRYTHNG actions to the IOTA Distributed Ledger Technology (DLT) and its networks.
IOTA is an open source DLT that enables sharing of any type of data (including IoT data) guaranteeing traceability of their source, alongside with integrity and immutability of the shared information, and dedicated access management, e.g., who can read what. In contrast with traditional blockchain-based DLTs, IOTA is based on a Directed Acyclic Graph, the Tangle. This video explains how the IOTA’s Tangle works.
The IOTA Streams second layer protocol is used to create chains of messages anchored to the Tangle. The anchors library facilitates getting access to the IOTA Streams functionality through the abstraction of an "Anchoring Channel".
- Deploy this Reactor script in an application within a project, not
forgetting to specify the
dependencies
inpackage.json
. - You can specify a
NODE_ADDRESS
, otherwisehttps://chrysalis-nodes.iota.org
will be used (see Testing below). - Ensure that the
CONFIRMATION_ACTION_TYPE
action type exists in the same project as the EVRYTHNG application hosting the Reactor script.
The script will react to actions with a sendToIOTA=true
custom field
and will record a transaction for the action on the IOTA Distributed Ledger (DLT).
The script will record transactions on the Chrysalis mainnet default nodes (hosted
by the IOTA Foundation) unless a specific node is defined by the NODE_ADDRESS
setting.
You can include any extra custom fields that you may require in addition to the one mentioned here. The target of the original action can be either a Thng, product, or collection.
Once the script has run, the resulting channelID
, seed
and publicKey
are added
to the target Thng, product, or collection's custom fields under a dictionary named
iotaAnchoringChannel
. The channelID
is the combination of the channel address
and the initial anchorage (announce message) provided by the anchoring
channel associated to the target. The seed
is the secret used to create such a channel
and to anchor action's hashes. Such seed is used to generate an Ed25519 key pair which
public key component is stored under the publicKey
custom field. The public key allows
to verify the authenticity of the anchored messages when fetched.
Last but not least, the iotaAnchoringChannel
dictionary contains the nextAnchorageID
member which allows the Reactor script to continue anchoring messages to the same IOTA Streams
channel (i.e.: in a single chain) on subsequent invocations. This allows the anchoring channel
to closely resemble the target's action history.
Once the script is installed, test it by creating an action with the correct
custom field specified on a Thng
, product
, or collection
in the project's scope,
for example:
{
"type": "_ItemShipped",
"thng": "UKn4wYKEYyQnc2aawGhytBfc",
"customFields": {
"sendToIOTA": true
}
}
The confirmation action created by the script will contain the channelID, as well as a pointer to the original action that triggered the script:
{
"type": "_sentToIOTA",
"id": "VasQR7nVxNMmYMUNxYMwpFap",
"createdAt": 1626279332221,
"customFields": {
"channelID": "5f9bf50c1e569935e8dee6885623b218653bec4974336f35bb496799479f6dbe0000000000000000:0e39dbea0bf5ded36b7ae626",
"originalAction": {
"id": "Vw8Qw7Ha7gNsSfg2MNChAqQe",
"type": "_bottleOpened"
},
"publicKey": "5f9bf50c1e569935e8dee6885623b218653bec4974336f35bb496799479f6dbe"
},
"timestamp": 1626279332221,
"location": {
"latitude": 39.0481,
"longitude": -77.4728,
"position": {
"type": "Point",
"coordinates": [
-77.4728,
39.0481
]
}
},
"locationSource": "geoIp",
"createdByProject": "Vwrya4hYsEXpPxcxtxGEHrHa",
"createdByApp": "VasP3WkKBDTfT9Ertk4abmQb",
"thng": "Vw89wM7ntBfq9FVeEy9EYqbm",
"product": "VRNr4p4ysF5FBFCHMPRNehnh"
}
You can also inspect the anchoring channel content by using the tangle-cli tool. For instance,
tcli channel inspect --channelID="0d00913710aa876fadfb7aa3a7c1f99399dea03c442111f82976bf41df9dd0b50000000000000000:99c47f5045a0b27876a68087" --seed=jjfwzxqfmbpqiqrqiyntmdtucqxfgwapzciywutlarkzbixerisfqlxkqsgajvpyofmuktweqltnniup --mainnet