CubWallet Docs
中文

API reference

Every method goes through the same entry point:

js
const result = await window.bitshares.request({ method, params });

Only the four methods below are implemented.

bts_chainId

Returns the chain id and network id of the network currently selected in the wallet. A dApp cannot switch networks through the API; it can only read. When the user switches in the wallet, the page receives chainChanged.

Parameters: none (params is ignored).

Return value:

json
{
  "chainId": "4018d7844c78f6a6c41c6a552b898022310fc5dec06da467ee7905a8dad512c8",
  "network": "mainnet"
}
FieldTypeMeaning
chainIdstring64-character hex chain id (no 0x prefix)
network"mainnet" \"testnet"Wallet network id

See Mainnet and testnet for the exact values. You do not need to connect accounts first.

bts_accounts

Returns the accounts the user has already authorized for this origin on the current network. It does not open an approval window.

Parameters: none.

Return value: { id, name }[]. For example:

json
[
  { "id": "1.2.0", "name": "committee-account" }
]

The method returns an empty array [], not an error, when:

Permissions are stored per origin and network. Accounts authorized on mainnet do not appear automatically on testnet.

bts_requestAccounts

Asks the user to authorize wallet accounts on the current network for this origin.

Parameters: none. The dApp cannot name the accounts in the request; the user selects them in the approval window.

Return value: the same shape as bts_accounts, { id, name }[].

Behavior:

  1. If this origin already has authorized accounts on the current network and the wallet is unlocked, those accounts are returned immediately, with no popup.
  2. Otherwise a connect window opens, listing the wallet's accounts on the current network (including watch-only accounts). The user must select at least one.
  3. After approval, the permission is written to extension storage and the promise resolves with the selected accounts.
  4. Rejecting the window fails with 用户拒绝了请求; closing it fails with 用户关闭了确认窗口; leaving it for 5 minutes fails with 请求超时.

An origin may have only one pending approval at a time, otherwise you get 该站点已有待处理的请求. The wallet allows at most 5 pending approvals in total, otherwise 待处理请求过多.

A watch-only account can be authorized (it will appear in bts_accounts) but cannot sign. Signing with it fails with 账户 <id> 在钱包中没有私钥.

Only the user can revoke a site's permission, from the wallet settings. There is no dApp method to revoke. A “disconnect” control on your page only clears your local cache; it does not change the wallet's stored permission.

bts_signTransaction

Builds and signs a transaction without broadcasting it. The approval window is labelled as sign-only. Use this to preview or debug, or if you will submit the signed transaction to a node yourself.

Parameters:

json
{
  "operations": [
    ["transfer", { "from": "1.2.0", "to": "1.2.17", "amount": { "amount": "1", "asset_id": "1.3.0" }, "extensions": [] }]
  ]
}
FieldTypeMeaning
operationsarray of length 1–10Each item is [type, data]. The type may be an operation name string (preferred, e.g. "transfer") or a numeric id (e.g. 0)

Do not send ref_block_num, ref_block_prefix, a transaction-level expiration or signatures: the wallet uses only operations. It fills in the fee, the reference block and the transaction expiration. See Operation types for field layouts.

Return value:

json
{
  "txid": "…64 hex characters…",
  "broadcasted": false,
  "signed_transaction": {
    "ref_block_num": 12345,
    "ref_block_prefix": 67890,
    "expiration": "2026-12-01T03:00:00",
    "operations": [],
    "extensions": [],
    "signatures": ["…"]
  }
}

expiration is a chain UTC timestamp with no zone suffix (YYYY-MM-DDTHH:MM:SS).

Preconditions:

The call opens an approval window. The window is filled from a decode of the transaction bytes plus chain lookups (account names, asset symbols, decrypted memos, pool quotes, risk flags), not by echoing your JSON.

bts_signAndBroadcast

Uses the same parameters and the same checks as bts_signTransaction. The only difference is that after the user approves, the wallet broadcasts the signed transaction to the current node.

Return value: the same shape; broadcasted is true after the node accepts the transaction.

This is a write that changes chain state. Call it only after the user clearly clicks “submit / broadcast / send to the chain”, never on load, navigation or a timer. On the test dApp these buttons are marked as broadcast actions and require a click.

If the user rejects the approval window, the transaction is neither signed nor broadcast.