2

I make a web application, that needs the events from my contract to initialize it's state. I was using infura websocket provider, but it seems to lag a lot and close the connections unexpectedly during the last week. getPastEvents method does not work well.

I would like for my application to be accessible from smartphones (at least for read only mode). So I cannot rely only on the node or wallet running on same computer.

Is there a way to get all the events from some contract in a reliable way? For example, how does etherdelta achieve this? They run a server, with it's own private node, that generates static data every block?

0

You can use event watch on each transaction call then able to get the event from Tx receipts.

Sample code

const self = this;
this.props.deposit(this.state.amount).then((result) => {
    if (!result) {
        Message.error('XYZ')
    }

    var event = self.props.getEventXXX()
    event.watch(function (err, response) {
        if(response.event == 'XXX') {
            notification.success({
                message: 'ABC',
                description: 'XYZ!',
            });
            event.stopWatching()
        }
    });

You can refer to this document also: https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-events

  • That's a good idea! But I really need to load the past events. It would be to costly to store all the needed information in the contract. – Rob Yart Aug 29 '18 at 19:41
  • You can get past events of any specific transaction from it's receipts/logs and it's not called listening to events as your title; just read data from blockchain. – Ha ĐANG Aug 30 '18 at 2:32

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.