Skip to content

Events

The Provider will be implemented per the Node.js EventEmitter API with the following event-handling methods:

  • on
  • off
  • addListener
  • removeListener

Example Usage

function handleActiveAccountChanged(accountAddress) {
  // handle active account
}
// subscribe to the activeAccountChanged event
window.xpll.on("activeAccountChanged", handleActiveAccountChanged);
// unsubscribe the activeAccountChanged event
window.xpll.off("activeAccountChanged", handleActiveAccountChanged);

Event Message Type

When emitted, the event will be emitted with an object argument of the following form:

interface ProviderMessage {
  readonly type: string;
  readonly data: unknown;
}

Network Changed

If the network that the Provider is connected to is changed, the Provider will emit the event named networkChanged with string as the network id.

interface NetworkChangedEvent {
  readonly type: "networkChanged";
  readonly data: string;
}

Active Account Changed

If the current active account is changed, the Provider will emit the event named activeAccountChanged with string as the account address.

interface ActiveAccountChangedEvent {
  readonly type: "activeAccountChanged";
  readonly data: string;
}

Warning

The activeAccountChanged event will only fire after permission has been granted. Please check Permissions for more details.

Lock State Changed Event

If the lock state of the wallet is changed, the Provider will emit the event named lockStateChanged with boolean as the wallet lock state.

export interface LockStateChangedEvent extends ProviderMessage {
  readonly type: "lockStateChanged";
  readonly data: boolean;
}