CubWallet Docs
中文

Events

Subscribe with provider.on(event, fn) and unsubscribe with provider.removeListener(event, fn). Exceptions thrown in a listener are swallowed and do not stop other listeners.

The provider currently pushes only the three events below. There is also a DOM announcement event on window; see Detect the wallet.

lock

Fired when the wallet is locked (the user locked it, or the auto-lock timer fired). No payload.

After a lock:

js
bts.on('lock', () => {
  renderDisconnected();
});

unlock

Fired when the wallet is unlocked successfully. No payload. A typical response is to call bts_accounts again and restore the authorized accounts.

js
bts.on('unlock', async () => {
  const accounts = await bts.request({ method: 'bts_accounts' });
});

chainChanged

Fired when the user switches the network in the wallet. The payload is:

json
{
  "chainId": "39f5e2ede1f8bc1a3a54a7914414e3779e33193f1f5693510e73cb7a87617447",
  "network": "testnet"
}

The fields match the return value of bts_chainId. A dApp cannot request a network switch. When this event arrives, update the network indicator on the page and call bts_accounts again (permissions are stored per network, so the account list often changes).

js
bts.on('chainChanged', async (data) => {
  console.log(data.network, data.chainId);
  const accounts = await bts.request({ method: 'bts_accounts' });
});

bitshares#initialized

This is not a provider.on event. It is a DOM event on window, dispatched once after window.bitshares is installed. See Detect the wallet.