0

In order to watch an event we can use:

var temp;
eventx.watch (function(error, result){ temp = result.args.val.toNumber();});

Question 1: What is the role of:

function(error, result){ temp = result.args.val.toNumber();}

and why does not it have any name?

Question 2: What does it return?

In general, what are the arguments of watch function?

1 Answer 1

1
  1. This is referred to as an 'anonymous function', a function without a name. It doesn't have a name because in this context it doesn't need one as we never need to refer to it outside of this scope. In this context it is used as a 'callback' which will be called when the watch function observes an event occurring and passes it to the callback function as either an error or a response.
  2. The doc for events in web3js pre 1.0, which I believe is what the function above is using, can be found here and it specifies the parameters and return values. You should also check out the web3js 1.0 doc for events as there is a couple of new methods there. They also specify the parameters of the functions and what they return.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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