Taxonomy Icon

Blockchain

Leverage blockchain monitoring

Get the code Watch demo 1 Watch demo 2

Summary

Create an application that provides a UI that allows operators to monitor the progress of IoT assets as they move through a supply chain. This is done by utilizing the Hyperledger Fabric SDK to query a blockchain service. In addition to being able to view individual blocks and their transactions, operators can use the UI to leverage chaincode operations, which have the ability to register new assets and view/update their properties.

Description

With IoT turning out to one of the most disruptive and useful forms of technology, have you ever wondered how to prevent IoT devices from being compromised? Or how to prevent data from being lost due to corruption, accidental deletion, etc.? Or perhaps how to allow interested parties to see the state of IoT devices without compromising security?

In this developer code pattern, we will demonstrate a blockchain monitoring application using React and Node.js with the Hyperledger Fabric SDK. This integration allows users to easily execute actions against the blockchain network and monitor the state of assets.

When you have completed this code pattern, you will understand how to:

  • Deploy a Hyperledger Blockchain network on IBM Cloud
  • Create and enroll an administrative client using the Hyperledger Node SDK
  • Deploy and instantiate a smart contract to handle asset updates/queries
  • Create a schema describing the properties of an asset
  • Monitor and propose blockchain transactions via a UI
  • Integrate IBM Watson™ IoT platform to directly receive asset updates from registered IoT devices via MQTT or HTTP

Flow

flow

  1. Request is submitted to create, read, update, or delete an asset from a blockchain ledger. This request may be submitted manually by a user via the monitoring UI browser or from an IoT device (NFC/barcode scanner, etc.) publishing an MQTT message to the Watson IoT platform.

  2. Express.js back-end formats CRUD request into a JSON-RPC object like below and submits to a Hyperledger peer as a transaction proposal

{
    jsonrpc: '2.0',
    method: 'invoke',
    params: {
        type: 1,
        chaincodeID: {
            name: 'simple_contract'
        },
        ctorMsg: {
            function: 'createAsset',
            args: '["assetID",
  {"carrier": "Port of Long Beach",
  "longitude":"33.754185", "latitude":
  "-118.216458", "temperature": "44 F"}]'
        },
        secureContext: 'kkbankol@us.ibm.com'
    },
    id: 5
}
  1. Peer uses an “endorsement” service to simulate the proposed transaction against the relevant smart contracts. This service confirms that the transaction is possible, given the current state of the ledger. Examples of invalid proposals might be creating an asset that already exists, querying the state of an asset that does not exist, etc.

  2. If the simulation is successful, the proposal is then “signed” by the peer’s endorser.

  3. The signed transaction is forwarded to an ordering service, which executes the transactions and places the result into the ledger.

  4. The monitoring UI auto-refreshes to show the transaction result and updated ledger in the response payloads and blockchain columns.