Event Emitter Methods
The EventEmitter API allows applications to use an Observer Pattern to register callbacks for when various events occur.
This closely follows the Event Emitter provided by other JavaScript libraries with the exception that event names support some more complex objects, not only strings. The objects are normalized internally.
Notify all listeners of the eventName event, passing args to each listener. This is generally only used internally.
Remove a listener for the eventName event. If no listener is provided, all listeners for eventName are removed.
Remove all the listeners for the eventName event. If no eventName is provided, all events are removed.
Returns the number of listeners for the eventName event. If no eventName is provided, the total number of listeners is returned.
Any of the following may be used as the eventName in the above methods.
A filter is an object, representing a contract log Filter, which has the optional properties
accountLike
(the source contract) and topics
(a topic-set to match).The value of a Transaction Filter is any transaction hash.
This event is emitted on every mined transaction. It is much more common that the
once
method is used than the on
method.In addition to transaction and filter events, there are several named events.
provider.once(transactionId, (transaction) => {
// Emitted when the transaction has been mined
})
// This filter could also be generated with the Contract or
// Interface API. The address must be specified, if topics is not specified,
// any log matches.
filter = {
address: "",
topics: [
utils.id("Transfer(address,address,uint256)")
]
}
provider.on(filter, (log, event) => {
// Emitted whenever a DAI token transfer occurs
})
provider.on("pending", (tx) => {
// Emitted when any new pending transaction is noticed
});
provider.on("error", (tx) => {
// Emitted when any error occurs
});
Returns true if and only if object is a Provider.
Last modified 1yr ago