Hethers
  • Documentation
  • Getting Started
  • Application Programming Interface
    • Providers
      • Provider
        • Accounts Methods
        • Logs Methods
        • Network Status Methods
        • Transactions Methods
        • Event Emitter Methods
        • Base Provider
        • HederaProvider
      • Types
    • Contract Interaction
      • Contract
      • ContractFactory
      • Example: ERC-20 Contract
    • Utilities
      • Accounts
      • Addresses
      • Application Binary Interface
        • AbiCoder
        • ABI Formats
        • Fragments
        • Interface
      • BigNumber
      • Byte Manipulation
      • Constants
      • Display Logic and Input
      • Encoding Utilities
      • FixedNumber
      • Hashing Algorithms
      • HD Wallet
      • Logging
      • Property Utilities
      • Signing Key
      • Strings
      • Transactions
      • Web Utilities
      • Wordlists
    • Signers
  • Contributing
  • Other Resources
Powered by GitBook
On this page
  • Events
  • Inspection Methods
  1. Application Programming Interface
  2. Providers
  3. Provider

Event Emitter Methods

PreviousTransactions MethodsNextBase Provider

Last updated 3 years ago

The EventEmitter API allows applications to use an 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 .

provider.once( eventName , listener ) ⇒ this

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

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

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

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

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

provider.removeAllListeners( [ eventName ] ) ⇒ this

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

provider.listenerCount( [ eventName ] ) ⇒ number

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

provider.listeners( eventName ) ⇒ Array< Listener >

Events

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

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: [
        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
});

Inspection Methods

Provider.isProvider( object ) ⇒ boolean

Returns true if and only if object is a Provider.

Returns the list of Listeners for the eventName .

See for more information on filtering events.

Observer Pattern
event
event
event
event
event
event
event
EventFilters