Skip to main content

Events and provider state

Listen to provider events so your app stays in sync when the user changes account, network, lock state, or UTXO state.

EVM events

window.ethereum.on('accountsChanged', (accounts) => {
console.log('EVM accounts', accounts);
});

window.ethereum.on('chainChanged', (chainId) => {
console.log('EVM chain', chainId);
});

window.ethereum.on('disconnect', (error) => {
console.warn('Provider disconnected', error);
});

Pali custom events

Pali also emits custom wallet notifications used by the extension provider.

EventMeaning
pali_accountsChangedThe connected account changed.
pali_chainChangedThe active chain changed.
pali_unlockStateChangedThe wallet lock state changed.
pali_isBitcoinBasedThe active UTXO family changed.
pali_xpubChangedThe connected UTXO xpub changed.
pali_blockExplorerChangedThe active UTXO explorer changed.

Provider state methods

const evmState = await window.ethereum.request({
method: 'wallet_getProviderState',
});

const sysState = await window.pali.request({
method: 'wallet_getSysProviderState',
});

Provider state is useful for initialization, but do not treat it as a substitute for explicit account permission checks.