Emit events from Blockchain Platform V2.0

Get the code

Summary

In this developer code pattern, you’ll learn how to emit events from the blockchain network so external applications can subscribe to them and take action. More importantly, you will learn how to do this through an application that is built on top of an IBM Kubernetes Service cluster with IBM Blockchain Platform V2.0. As you’ve seen, blockchain’s trusted and immutable shared ledger is the foundation for innovative business solutions. Applications and external systems often need to know when something happens to the shared ledger. This pattern will show you how to programmatically generate and receive those notifications when transactions are written to the blockchain network.

Description

Note: This developer pattern is the third in a series of patterns designed to get you started with blockchain. For an overview of the series, see Build your first blockchain application.

This pattern should be tackled once you are skilled in creating network and smart contracts using the IBM Blockchain Platform V2.0 service. Consider this pattern an extension of that knowledge. Currently, this application demonstrates the event handling by extending the fabcar use case. Events occur when a car listing is issued. Participants interested in purchasing cars from an auction ask for notification when car sale listings are posted so they can get an early chance to bid. This pattern can be extended so that when a deal is closed, the owner is notified so they can anticipate when they will receive payment. Event notifications are an important part of the blockchain technology as participants typically like to react appropriately when transactions occur.

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

  • Package up your blockchain smart contracts using the IBM Blockchain Platform Extension for VS Code
  • Set up a Hyperledger Fabric network on IBM Blockchain Platform V2.0
  • Install and instantiate a smart contract package through IBM Blockchain Platform V2.0
  • Deliver code that registers a callback function to receive a notification when a transaction has been committed to a block
  • Execute a Node.js application with the Hyperledger Fabric SDK to interact with the deployed network and issue and catch transactions

Flow

flow

  1. Developer develops a smart contract using Node.js.
  2. Use the IBM Blockchain Platform Extension for VS Code to package the decentralized energy smart contract.
  3. Set up and launch the IBM Blockchain Platform V2.0 service.
  4. IBM Blockchain Platform V2.0 enables the creation of a network onto an IBM Kubernetes service, enabling installation and instantiation of the auction smart contract on the network.
  5. Node.js application uses the Fabric SDK to add a listener to specific transactions and subsequently interact with the deployed network on IBM Blockchain Platform V2.0 and issue transactions.
  6. Events emitted as transactions are triggered, and blocks are committed to the ledger. The events are sent back to the Node.js application.

Instructions

Please see the README to get started.