Skip to main content

Events

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

Applications can subscribe to account and network changes and refresh page data after the user switches wallet status:

accountsChanged

Triggered when the user switches BTC accounts or disconnects authorization.

window.$ukey.btc.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.$ukey.btc.off('accountsChanged');

networkChanged

Triggered when user switches BTC network. After the network changes, re-read the status related to the account, balance and address format.

window.$ukey.btc.on('networkChanged', (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.$ukey.btc.off('chainChanged');