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.

provider.on( eventName , listener ) ⇒ this

Add a listener to be triggered for each eventName event.

provider.once( eventName , listener ) ⇒ this

Add a listener to be triggered for only the next eventName event, at which time it will be removed.

provider.emit( eventName , ...args ) ⇒ boolean

Notify all listeners of the eventName event, passing args to each listener. This is generally only used internally.

provider.off( eventName [ , listener ] ) ⇒ this

Remove a listener for the eventName event. If no listener is provided, all listeners for eventName are removed.

provider.removeAllListeners( [ eventName ] ) ⇒ this

Remove all the listeners for the eventName event. If no eventName is provided, all events are removed.

provider.listenerCount( [ eventName ] ) ⇒ number

Returns the number of listeners for the eventName event. If no eventName is provided, the total number of listeners is returned.

provider.listeners( eventName ) ⇒ Array< Listener >

Returns the list of Listeners for the eventName event.


Any of the following may be used as the eventName in the above methods.

Log Filter

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).

See EventFilters for more information on filtering events.

Transaction Filter

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: [

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

Inspection Methods

Provider.isProvider( object ) ⇒ boolean

Returns true if and only if object is a Provider.

Last updated