Skip to main content

Events

The Nostr Provider uses an event model similar to Node.js EventEmitter.

The application can monitor account changes and refresh the local state after the user switches identities:

accountsChanged

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

window.nostr.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.nostr.off("accountsChanged");

chainChanged (deprecated)

This event is deprecated. If the old environment still triggers it, re-read the Provider state.

window.nostr.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.nostr.off('chainChanged');