Skip to main content

Events

WebLN Provider uses an event model similar to Node.js EventEmitter.

Applications can listen for account changes and refresh local state if necessary:

accountsChanged

Triggered when the user switches accounts or the authorization status changes.

window.webln.on('accountsChanged', (accounts) => {
// Handle newly exposed accounts, or the case where there are no accounts.
// "accounts" will always be an array, though it can be empty.
});
window.webln.off('accountsChanged');

chainChanged (deprecated)

This event is deprecated. If the old environment still triggers it, refresh the page and re-read the Provider status.

window.webln.on('chainChanged', (chainId) => {
// Handle the newly selected chain.
// Handling chain changes correctly can be a little involved.
// Unless you have a strong reason not to, reloading the page is the simplest approach.
window.location.reload();
});
window.webln.off('chainChanged');