Blockchain-IoT based Man­age­ment of Shared Re­sources be­tween Trust­less Par­ties

In this ar­ti­cle, the au­thors dis­cuss use cases for which blockchains and IoT de­vices can be used, in­stead of in­ter­me­di­aries, for Trust­less par­ties to trans­act with each other. The au­thors also dis­cuss the ar­chi­tec­ture and the open source tech­nolo­gies that

OpenSource For You - - Contents - By: Venkat­acha­lam Subra­ma­nian and Su­manta Basu Venkat­acha­lam Subra­ma­nian is a prin­ci­pal con­sul­tant in tal­ent trans­for­ma­tion, Wipro Lim­ited, Ben­galuru. He has 20 years of ex­pe­ri­ence in the IT in­dus­try. Su­manta Basu is a se­nior ar­chi­tect in the com­mu­ni­ca­tio

Gov­ern­ments, com­mu­ni­ties or com­pa­nies of­ten need to track, con­trol and man­age as­sets and re­sources that they have a shared in­ter­est in. For ex­am­ple, in the lo­gis­tics in­dus­try, a per­ish­able item might get trans­ported from a sender to a re­ceiver. While in tran­sit, the per­ish­able item may have to be kept un­der a cer­tain tem­per­a­ture or pres­sure. The item may get trans­ported through mul­ti­ple modes such as ship, train, truck, etc, and mul­ti­ple trans­port op­er­a­tors might be in­volved be­fore it reaches its des­ti­na­tion. Pay­ments have to be re­leased to these par­ties if and only if they trans­ported the item as per the con­tract.

Of­ten, there is no trust be­tween the sender, re­ceiver and the var­i­ous par­ties in­volved. This means that the pa­ram­e­ters re­quired to pre­serve a per­ish­able item have to be tracked and con­trolled. And there needs to be a ver­i­fi­able record of this track­ing/con­trol­ling through­out the trans­porta­tion pe­riod. There is also a need for a trusted way to set­tle pay­ments be­tween the var­i­ous par­ties once the ship­ment has been de­liv­ered as per the con­tract.

An­other use case is in the en­ergy sec­tor, where smart grids are used for the dis­tri­bu­tion and con­sump­tion of elec­tric power. There is a need for power gen­er­a­tors and dis­trib­u­tors to track the sup­ply and dis­tri­bu­tion of power, and keep records of it, to even­tu­ally rec­on­cile and set­tle ac­counts be­tween the pro­duc­ers and dis­trib­u­tors of power. A third use case could be to man­age water re­sources stored in dams and shared be­tween coun­tries/states.

The list of such use cases is end­less. Of­ten these par­ties do not trust each other and end up ap­point­ing an in­ter­me­di­ary third-party trusted by all of them to man­age, con­trol or track the re­sources, on their be­half. The in­ter­me­di­aries, how­ever, may charge ex­or­bi­tant fees for their ser­vices or may be­come

in­ef­fec­tive due to po­lit­i­cal/com­mer­cial rea­sons. Blockchain and IoT tech­nolo­gies to­gether pro­vide a so­lu­tion which can do away with the in­ter­me­di­aries and au­tonomously track, con­trol and man­age re­sources in a trusted way.


The blockchain is a peer-to-peer net­work. It is based on a shared ledger (the blockchain data­base) and a pro­to­col to keep the shared ledger up­dated. It is the tech­nol­ogy un­der­ly­ing Bit­coin, the fa­mous crypto-cur­rency. Bit­coin was cre­ated by an un­known per­son nick­named Satoshi Nakamoto. For peo­ple to ac­cept and adopt Bit­coin as a crypto-cur­rency, they had to be able to trust it. But, there is no gov­ern­ment back­ing this crypto-cur­rency. So, the trust has to be pro­vided by the Bit­coin net­work it­self.

The tech­nol­ogy that pro­vides such trust for Bit­coin is the blockchain. It is a shared ledger which is avail­able on each full node of the net­work. In a Blockchain, each block is anal­o­gous to a ledger page and the blockchain is anal­o­gous to a ledger book. When a Bit­coin trans­ac­tion hap­pens on the net­work, the miner nodes ver­ify the va­lid­ity of the trans­ac­tion, ar­rive at a con­sen­sus and up­date their copy of the ledger. The trans­ac­tions ver­i­fied and en­tered in the blockchain are im­mutable. Since blockchain is a peer-to-peer net­work, it does not have a cen­tral server. It has only peer level client ap­pli­ca­tions, which join the blockchain net­work as nodes.

A blockchain pro­vides some key ben­e­fits, which can be lever­aged to pro­vide so­lu­tions for use cases such as the ones dis­cussed ear­lier in this ar­ti­cle. Since it is a shared ledger on a peer-to-peer net­work, it does not have any cen­tral server which can be shut down uni­lat­er­ally by any one party or author­ity. The records, trans­ac­tions and smart con­tracts up­dated in the blockchain are im­mutable. They can­not be mod­i­fied. The shared ledger is up­dated based on a con­sen­sus pro­to­col and hence it pre­vents users or those trans­act­ing with Bit­coins from mak­ing fraud­u­lent en­tries in the blockchain. This pro­vides the trust needed when par­ties un­known to each other have to trans­act with­out an in­ter­me­di­ary. Here, the blockchain net­work pro­vides the trust.

There are a few open source plat­forms such as Ethereum, Hyper­ledger and Stel­lar, us­ing which we can cre­ate a blockchain net­work as a pub­lic net­work, whereby any one can join the net­work. Al­ter­na­tively, it can also be a pri­vate net­work be­hind the fire­wall of an or­gan­i­sa­tion so that only those within the or­gan­i­sa­tion can join it; or as a per­mis­sioned blockchain, where only those who are per­mit­ted to join the blockchain can do so.

Smart con­tracts

The fea­tures of Blockchain, such as de­cen­tral­i­sa­tion, im­mutabil­ity, ver­i­fi­ca­tion, con­sen­sus and not be­ing able to shut it down, pro­vide a trustable net­work which can re­place any in­ter­me­di­ary. Soon, many peo­ple re­alised that the blockchain has the po­ten­tial to be used for ap­pli­ca­tions beyond crypto-cur­rency such as Bit­coin. It can be used as a plat­form to execute or en­force con­tracts be­tween un­known and hence un­trusted par­ties in the form of smart con­tracts. But this needed a Tur­ing Com­plete blockchain plat­form so that com­plex busi­ness logic could be writ­ten as code. The Bit­coin blockchain is not Tur­ing Com­plete by de­sign to avoid hacks. Hence, smart con­tracts can­not be writ­ten on the Bit­coin blockchain. This lim­i­ta­tion gave rise to other blockchain plat­forms which can be used to write smart con­tracts, such as Ethereum, Hyper­ledger, etc.

Smart con­tracts are posted on the blockchain net­work in the same way we send crypto-cur­rency. The posted con­tracts are added to the shared ledger (blockchain data­base). Smart con­tracts im­ple­ment com­plex busi­ness logic as code. Each smart con­tract will have an ad­dress to which mes­sages can be posted. A smart con­tract ex­e­cutes upon get­ting the mes­sages posted to its ad­dress.

A client ap­pli­ca­tion con­nected to the blockchain net­work can re­ceive mes­sages from real-world as­sets such as IoT de­vices and post them to the smart con­tract. On get­ting the mes­sage, the smart con­tract ex­e­cutes and sends the re­sult back to the client ap­pli­ca­tion in the form of an asyn­chro­nous event. This event can be used to con­trol/man­age the re­al­world as­sets.

In a way, smart con­tracts are anal­o­gous to the stand­ing in­struc­tions given to banks to per­form tasks such as trans­fer­ring money to an­other ac­count on spe­cific dates, pay­ing util­ity bills, etc. But, smart con­tracts im­ple­ment more com­plex busi­ness logic and lever­age the prop­er­ties of the blockchain such as de­cen­tral­i­sa­tion, im­mutabil­ity and trust.


IoT (In­ter­net of Things) is a net­work of things in the phys­i­cal world. These things may be de­vices which have sen­sors within them or at­tached to them. In the con­text of IoT, a ‘thing’ is a server which is ca­pa­ble of get­ting sen­sor data from the de­vice and send­ing it to the back­end ap­pli­ca­tions. A ‘thing’ server can be any­thing – a car, a re­frig­er­a­tor, a ma­chine, a sur­veil­lance cam­era, a fan, a light, etc. IoT uses a lo­cal gate­way server to con­nect the var­i­ous thing servers in a build­ing, car, etc, to the back­end ap­pli­ca­tion. Thing servers use var­i­ous com­mu­ni­ca­tion tech­nolo­gies such as RFID, NFC, Wi-Fi, Blue­tooth, and

ZigBee to send data to the gate­way server. Thing servers can also have wide area con­nec­tiv­ity such as GSM, GPRS, 3G and LTE. On top of this com­mu­ni­ca­tion in­fra­struc­ture, IoT uses the MQTT pro­to­col to con­nect the thing servers with the back­end ap­pli­ca­tions.

MQTT mes­sag­ing pro­to­col

The IoT thing servers may gen­er­ate var­i­ous types of data. Dif­fer­ent back­end ap­pli­ca­tions might be in­ter­ested in dif­fer­ent types of data. The data ex­change be­tween the thing servers and the back­end ap­pli­ca­tions should hap­pen asyn­chronously. There should not be any de­pen­dency on both of them to be alive at the same time to send and re­ceive data.

To ad­dress this kind of a need, a pub­lish/sub­scribe bro­ker can be used in the ar­chi­tec­ture. HiveMQ is an open source pub­lish/sub­scribe bro­ker which uses the MQTT pro­to­col to talk to the IoT thing servers on the one hand and to the back­end ap­pli­ca­tions on the other. The MQTT pro­to­col works on the ba­sis of top­ics. IoT thing servers can regis­ter top­ics with the HiveMQ bro­ker. They will pub­lish sen­sor data as mes­sages on those top­ics. The back­end servers will sub­scribe to those mes­sages.

Once an IoT thing server pub­lishes a mes­sage on a spe­cific topic, the HiveMQ bro­ker sends that mes­sage to all the back­end servers which have sub­scribed to that topic. Sim­i­larly, if the back­end servers want to send any con­trol in­for­ma­tion to the

IoT thing servers, they can regis­ter the con­trol top­ics with the HiveMQ bro­ker and the IoT thing servers can sub­scribe to those top­ics. This will es­tab­lish a two-way com­mu­ni­ca­tion be­tween the IoT things and the back­end servers us­ing the MQTT pro­to­col and the HiveMQ bro­ker.


We did a Proof of Con­cept (PoC) im­ple­men­ta­tion us­ing IoT, blockchain and MQTT to con­trol a trans­ducer. The build­ing blocks of the PoC, and the open source tech­nolo­gies with which they were im­ple­mented, are ex­plained be­low:

A cloud based HiveMQ server was used as the MQTT pub­lish/sub­scribe bro­ker. On this bro­ker, the IoT thing server reg­is­ters a topic on which it pub­lishes the sen­sor data and the blockchain node reg­is­ters a topic on which it pub­lishes the con­trol data. In ad­di­tion, the IoT thing server sub­scribes to re­ceive the con­trol data while the blockchain node sub­scribes to re­ceive the sen­sor data. The HiveMQ bro­ker de­liv­ers the pub­lished mes­sages to sub­scribers. ESP8266-12 was used as the IoT thing server. This had a tem­per­a­ture, hu­mid­ity and light sen­sor. It reg­is­tered the sen­sor data topic with the cloud based HiveMQ MQTT bro­ker and pub­lished the sen­sor data on this topic. It sub­scribed to the con­trol mes­sages from the blockchain node. A Node.js Web ap­pli­ca­tion, which sub­scribes to the sen­sor data topic on the HiveMQ bro­ker for get­ting the sen­sor data, was used. It reg­is­ters the topic on which it pub­lishes the con­trol mes­sages on the HiveMQ bro­ker. Sub­se­quently, it pub­lishes the con­trol mes­sages re­ceived from the blockchain. This Web ap­pli­ca­tion was con­nected to an Ethereum blockchain us­ing the web3 JavaScript li­brary. It reg­is­ters the smart con­tract on the blockchain. It also posts the sen­sor data to the smart con­tract and watches for the asyn­chro­nous con­trol mes­sages from the smart con­tract. The con­trol mes­sages re­ceived from the smart con­tract are pub­lished through the HiveMQ bro­ker. The smart con­tract was writ­ten us­ing the So­lid­ity lan­guage and com­piled us­ing a Solc com­piler. The com­piled smart con­tract is posted to the Ethereum blockchain us­ing the web3 JavaScript li­brary from the blockchain node.

Lo­gis­tics use case

Let us again look at the lo­gis­tics use case men­tioned at the be­gin­ning of this ar­ti­cle and see how the so­lu­tion can be im­ple­mented. The per­ish­able items are packed in a con­tainer in which a thing server with the tem­per­a­ture/pres­sure sen­sors is fit­ted. The sen­sor data is pub­lished through the MQTT bro­ker.

The var­i­ous trans­port op­er­a­tors to­gether could form a con­sor­tium and start a blockchain net­work. In this case, the blockchain is a per­mis­sioned one, where the con­sor­tium con­trols who can join its blockchain. Only mem­bers of the con­sor­tium may be al­lowed to join the blockchain net­work. Al­ter­na­tively, the pub­lic Ethereum blockchain net­work can be used and the smart con­tract can be de­ployed on it.

The trans­port oper­a­tor may run a Web ap­pli­ca­tion on his node with an easy-to-use user in­ter­face to cre­ate the smart con­tract on the blockchain. The sender gets into a con­tract with the trans­port oper­a­tor. The terms and con­di­tions of the trans­porta­tion and pay­ment are coded as a smart con­tract and de­ployed on the blockchain. The pay­ment may be locked up in an es­crow ac­count.

The sen­sor data from the shipped con­tainer is re­ceived by the blockchain nodes and posted to the smart con­tract, which ver­i­fies the recorded tem­per­a­ture/pres­sure pa­ram­e­ters as per the cod­i­fied terms of the con­tract. Upon suc­cess­ful de­liv­ery of the item, the smart con­tract will trig­ger the pay­ment from the es­crow ac­count. The pay­ment will be com­pleted in near real-time.

In fu­ture, mi­cro pay­ments be­tween ma­chines and M2M (ma­chine-to-ma­chine) com­mu­ni­ca­tion with­out hu­man in­ter­ven­tion will find wide ap­pli­ca­tion. To­day’s cen­tralised client-server world is be­ing aug­mented with de­cen­tralised, peer-to-peer, dis­in­ter­me­di­ated dig­i­tal so­lu­tions. Blockchains with smart con­tracts and IoT are the evolv­ing tech­nolo­gies which will drive such an ex­cit­ing world.


The au­thors would like to ac­knowl­edge and thank Sri­ram Ra­jagopalan and Sarav Da­man of Wipro Lim­ited for their crit­i­cal re­view of the ar­ti­cle and con­tri­bu­tion dur­ing the im­ple­men­ta­tion of the PoC.

Fig­ure 1: Blockchain with smart con­tract

Fig­ure 3: IoT-blockchain PoC ar­chi­tec­ture So­lu­tion Ar­chi­tec­ture

Fig­ure 2: IoT thing server ar­chi­tec­ture

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.