Skip to content

Events and errors ​

Events ​

Use on to register a listener and off with the same function to remove it.

EventPayloadWhen it is emitted
accountsChangedstring[]Connection, disconnection, or active address change
accountChangedNoneActive account change
networkChangedbitcoin, mutinynet, or customNetwork change
lockNoneManual or automatic wallet lock
unlockNoneWallet unlock
js
const refresh = () => loadWalletData();
const clear = () => clearSensitiveData();

window.arkade.on('accountChanged', refresh);
window.arkade.on('networkChanged', refresh);
window.arkade.on('unlock', refresh);
window.arkade.on('lock', clear);

function cleanup() {
  window.arkade.off('accountChanged', refresh);
  window.arkade.off('networkChanged', refresh);
  window.arkade.off('unlock', refresh);
  window.arkade.off('lock', clear);
}

INFO

accountsChanged is scoped to the connected origin. After an account or network change, refetch the data shown by your App.

Error handling ​

Every method can reject its Promise with an Error. Always handle rejection, approval window closure, and locked state.

js
try {
  const txid = await window.arkade.sendToAddress(address, amountSats);
  showSuccess(txid);
} catch (error) {
  const message = error instanceof Error ? error.message : String(error);
  showError(message);
}

Recognizable messages ​

MessageMeaning
Not connected. Call connect() first.The origin is not authorized
Wallet is lockedA read requires an unlocked wallet
Wallet is locked. Open the extension, unlock it, then try again.An approval operation began while the wallet was locked
Invalid amount: must be a positive integerThe amount is zero, negative, or fractional
User rejected the connection requestThe user rejected or closed the connection request
User rejected the transactionThe user rejected or closed the send request
User rejected the signature requestThe user rejected or closed the signature request
User rejected the settlementThe user rejected or closed the settlement request
The active account or network changed while this request was open, so nothing was done. Ask the site to try again.The context changed during approval

Opening more than three approval windows for the same origin is also treated as a rejection. Server-side errors, such as insufficient funds or an amount below the minimum, are passed through with their original message.

TIP

Do not build the whole experience around matching error text. Use known messages for targeted guidance, but always provide a generic fallback and never show success before the Promise resolves.

Open-source products for programmable Bitcoin.