Events Listener

Methods related to the events listener.

The wallet emits events that can be listened to. It uses a pull mechanism under the hood, the pull interval can be passed to the constructor under the eventManagerParams.pullInterval key. Events will be pulled every pullInterval milliseconds if and only if there is at least one listener.

The default pull interval is 5 seconds.

Read Blockchain events

📌

This method listens events in background and trigger newer events.

Method

wallet.smartAsset.received.addListener(eventName)
ParameterTypeRequiredDescription
eventNameEnumEvent name.
callBackFunctionFunction to call each time an event occurs.
// pull events every 2 seconds
const wallet = new Wallet({
  eventManagerParams: {
    pullInterval: 2000,
  },
});

// listen to smart asset received event
wallet.smartAsset.received.addListener((event) => {
  const { certificateId, protocol } = event;
  console.log(`Smart asset (id ${certificateId}) received on ${protocol.name} (chain ${protocol.chainId})`);
});

Remove a type of event listener

Method

wallet.smartAsset.received.removeListener(listener);

Remove all events listener

Method

wallet.smartAsset.received.removeAllListeners();