Ethereum smart contract event trigger notification

0 votes

I am using a Ethereum smart contract which contains a trigger mechanism that is triggered every time a transaction is made. What I want is to get notified whenever the event is triggered. How can I implement a notification mechanism?

The event code is as follows:

event Transfer(address indexed from, address indexed to, uint to)

Aug 1, 2018 in Blockchain by digger
• 27,620 points
131 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

I have an example here for web3js 1.0.0.beta:

function handler (event) {

   console.log(event.returnValues);

}

function errorCallback (err) {

   console.error(err);

}

let subscription = contractObj.events.TestEvent().subscription;

subscription.on('data', handler).on('error', errorCallback);

/////// code to unsubscribe

subscription.unsubscribe(function (result) {

   console.log(result)

});

///// code for usage class

class Listener {

  constructor(event, handler) {

    this.subscription = event;

    this.subscription.on('data', handler).on('error', this.errorCallback);

  }

  errorCallback(err) {

    console.log(err);

  }

}

class Test {

  constructor(contractObj) {

    this.contractObj = contractObj;

    this.createListener();

  }\

  createListener() {

    let self = this;

    this.listener = new Listener(this.contractObj.events.TestEvent(), function (event) {

      self.returnValues = event.returnValues;

    });

  }

}

answered Aug 1, 2018 by slayer
• 29,040 points

Related Questions In Blockchain

0 votes
1 answer

How to get notified when an event triggers on ethereum smart contract?

Here's a simple example for web3js 1.0.0.beta*: function handler ...READ MORE

answered Jun 8, 2018 in Blockchain by ariaholic
• 7,320 points
245 views
0 votes
1 answer

Where are the transaction details of a smart contract is written in Ethereum?

First ques:where in the blockchain is a ...READ MORE

answered Jul 11, 2018 in Blockchain by Shashank
• 10,330 points
31 views
0 votes
1 answer

Error in sending value to an Ethereum Smart Contract.

It is stated in Solidity 4.0 documentation ...READ MORE

answered Jul 23, 2018 in Blockchain by Perry
• 16,450 points
32 views
0 votes
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
78 views
0 votes
1 answer
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 66,880 points
40 views
0 votes
1 answer

Error when trying to deploy Ethereum smart contract using web3j

Create a new credential based on the Credentials.create ...READ MORE

answered Oct 3, 2018 in Blockchain by slayer
• 29,040 points
118 views
0 votes
1 answer

How to store photos in Hyperledger smart contract?

To do this, you need to represent ...READ MORE

answered Jul 9, 2018 in Blockchain by slayer
• 29,040 points
51 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.