Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Blockchain by (4.1k points)

I previously worked on Ethereum which can generate "events" when a function is called or state is changed, and those events can be captured from the app by watching the state changes. Does Hyperledger have that functionality? I can see "events" in Hyperledger-fabric but how can I generate my own events and capture them in the node app when the state is changed?

1 Answer

0 votes
by (14.4k points)

Within Hyperledger Fabric, there is an API method that goes by the name shim.ChaincodeStubInterface. Using this API method, you can specify events during the invocation of chaincode. Further, you can register to the event hub for getting those events. 

The API method can be called as: 

SetEvent(name string, payload []byte) error

Note: SetEvent allows the chaincode to set an event on the response to the proposal to be included as part of a transaction. The event will be available within the transaction in the committed block regardless of the validity of the transaction.

Browse Categories