Wallet events

How apps can respond to user actions using wallet events

Sats Connect provides apps the ability to hook into key wallet events and provide a smoother experience. For example, when a user changes account, the wallet will emit a change account event that apps can use to update their UI or request permissions for the new account.

Hooking into events

To be notified of events, apps need to first connect to the wallet to receive account read permissions. Listeners registered using Wallet.addListener() will be notified of events for authorized accounts.

const removeListener = Wallet.addListener('accountChange', (event) => {
  console.log('The account has changed.', event);

  exampleUpdateUi();
  exampleRequestPermissionsForCurrentAccount();
});

// When no longer needed, the listener can be removed by calling the function
// returned by `addListener`.
removeListener();

Available events

The addListener method is typed to include all currently available events. They currently include:

  • accountChange

  • networkChange (coming soon)

The data passed to a listener callback is:

Note that for privacy reasons, account data is not part of the event payload. Apps must request the data upon receiving the event, and additionally ask for connection permissions for the changed account if they haven't already done so.

Last updated