7

I am new to hyperledger fabric. I have downloaded the fabric v1.2.0 and I tried to run fabcar example from the fabric-sample folder. My querying on the chaincode went well, but when I tried to invoke the chaincode I got the below error from the cmd.

This is my request to the chaincode

var request = {
    //targets: let default to the peer assigned to the client
    chaincodeId: 'fabcar',
    fcn: 'changeCarOwner',
    args: ['CAR4', 'Dave'],
    chainId: 'mychannel',
    txId: tx_id
};

Error:

Failed to invoke successfully :: TypeError: fabric_client.newEventHub is not a function

When I tried to find newEventHub in index.t.ds, I could not find the function. Can anyone help me with this.Thanks in advance.

Iain Duncan
  • 3,139
  • 2
  • 17
  • 28

2 Answers2

21

I think they've replaced the EventHub class with ChannelEventHub.

You can update the invoke.js file with following:

on line 105:

let event_hub = channel.newChannelEventHub('localhost:7051');
// event_hub.setPeerAddr('grpc://localhost:7053');

on line 130:

console.log('The transaction has been committed on peer ' + event_hub.getPeerAddr());

That should fix it.

Krishna Moniz
  • 498
  • 1
  • 6
  • 11
  • @Krishna Moniz After I did this I found another problem: Failed to invoke successfully :: TypeError: event_hub.setPeerAddr is not a function .. when I commented line 106 the transaction was successful but I believe setPeerAddr has been changed or ommitted from invoke.js ? – WowBow Aug 05 '18 at 09:04
  • 1
    I failed to notice that this changed from the fabric_client object to the channel object i.e. `fabric_client.newEventHub()` to `channel.newChannelEventHub('localhost:7051')` - so it took me longer to fix! – R Thatcher Sep 26 '18 at 15:48
  • the fix suggested in this answer worked for me as well. here is the updated code btw: https://github.com/hyperledger/fabric-samples/blob/release-1.2/fabcar/invoke.js showing usage of `newChannelEventHub` on line 105 – morpheus Nov 05 '18 at 19:38
4

Change the fabric-client npm version from "unstable" to ^1.2.1 in package.json and run npm install

vignesh679
  • 41
  • 2