1

I know how to handle events using personalised blockchain using ganache, can anyone tell me how to handle events in Kovan,rinkeby testnets?

  • Can you please share the code that works for you on Ganache but fails on other networks? Don't forget to describe exactly how it fails. – goodvibration Apr 24 at 18:40
  • initially, I'm creating a product. using productCreated function. And I have created events in smart contracts. And calling the event from the front end. Please find the below code. contractName.productCreated(id,name,age); contractName.events.ProductCreated({ fromBlock: 'latest', toBlock: 'latest' }, (err, result) => { if (err) {console.log(err)} else { console.log(result) //code to store the same result in the db using post request} }) While using ganache blockchain. I'm getting event after product created. but when using kovan test net, After product creation event not triggered – dinesh dsv Apr 24 at 19:23
1

fromBlock: 'latest', toBlock: 'latest'

On your Ganache private network, you are the only one who sends transactions.

So the events of your latest transaction will obviously be available to you on the latest block.

On the Kovan public network, there are others who send transactions as well.

So new blocks are added to the chain even when you are not sending anything, and by the time you try to fetch your events, the block which stores them is no longer the latest one in the chain.

| improve this answer | |
  • got it @goodvibration. But what should i need to do to get events in test net? Is there any solution to do that? – dinesh dsv Apr 25 at 21:37
  • I found the solution @goodvibration. I have added .once('receipt', (receipt) =>{this.setState({ receiptBC: receipt }); to my product Created function and then i retreived block number from recepit and changed fromBlock : blocknumber(from receipt). Thank you so much for your response. Cheers!! – dinesh dsv Apr 26 at 2:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.