CubWallet Docs
中文

Detect the wallet

window.bitshares

The extension injects a Object.freezed object into the page's MAIN world and defines it as window.bitshares (non-writable, non-configurable, enumerable). If the page already has an object under that name, the extension does not replace it.

The object has only these members:

MemberTypeMeaning
isCubWallettrueIdentifies the provider as CubWallet
isBtsWallettrueCompatibility flag for dApps written against BTS Wallet 0.16 and earlier. New code should check isCubWallet first
request({ method, params })PromiseCall an RPC method
on(event, fn)voidSubscribe to an event
removeListener(event, fn)voidUnsubscribe

There are no synchronous fields such as selectedAddress or chainId, and no enable() method. Read the network and accounts with request.

Announcement event bitshares#initialized

After the injection, the extension dispatches a regular DOM event on window:

js
window.dispatchEvent(new Event('bitshares#initialized'));

This is not a provider.on(...) event; listen with window.addEventListener('bitshares#initialized', ...). If the provider is already present when your script runs, the event will not fire again, so always do both:

js
function whenBitsharesReady(cb) {
  if (window.bitshares) {
    cb(window.bitshares);
    return;
  }
  window.addEventListener('bitshares#initialized', () => {
    if (window.bitshares) cb(window.bitshares);
  }, { once: true });
}

When the provider is injected

The background accepts a connection only when all of the following hold, and the page can use the provider only in those cases:

  1. The origin is https://host (a standard https origin, no path in the origin itself), or http://localhost[:port], or http://127.0.0.1[:port].
  2. The page is the top-level frame (frameId === 0). An iframe does not get the provider.
  3. The connection comes from this extension's content script (port.sender is set by the browser and cannot be forged by the page).

So:

The origin the wallet sees is port.sender.origin from the browser. A domain the page claims for itself is ignored. The same origin is shown in the approval window and used for permissions.

Recognizing CubWallet

js
const bts = window.bitshares;
if (bts?.isCubWallet) {
  // CubWallet
} else if (bts?.isBtsWallet) {
  // Older builds used this flag; CubWallet still sets it to true so existing dApps keep working
}

isBtsWallet will stay available. Do not treat it as “this is not CubWallet”.