Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listen to a custom chaincode event in Hyperledger Fabric

After using SetEvent() in the chaincode, how is possible to test it? Does exist some working example?

like image 675
Riccardo Persiani Avatar asked Nov 19 '25 20:11

Riccardo Persiani


1 Answers

You could create an application which is listening on the chaincode event.

I suggest you to have a look at the "Chaincode event listener" section of this link, which is the official Hyperledger Fabric Nodejs SDK.

https://fabric-sdk-node.github.io/tutorial-channel-events.html

First is necessary to configure the client correctly. Once it has been configured:

//... client configuration

var channel = fabric_client.getChannel();
var eventHub = channel.getChannelEventHubsForOrg(<NAME OF YOUR ORG>)[0];

eventHub.connect(true);
eventHub.registerChaincodeEvent(CHAINCODE_ID,EVENT_NAME,
    (event, block_num, txnid, status)=>{
        console.log('Successfully got a chaincode event with transid:'+ txnid + ' with status:'+status);
        console.log('Successfully received the chaincode event on block number '+ block_num);
        console.log(event);
    },
    (error)=>{
        console.log('Failed to receive the chaincode event ::'+error);
    }
);
like image 61
Leonardo Carraro Avatar answered Nov 23 '25 00:11

Leonardo Carraro