CubWallet Docs
中文

Best practices

Request only after a user click

bts_requestAccounts, bts_signTransaction and bts_signAndBroadcast can all open an approval window. Bind them to a button or another explicit user action. Do not call them on page load, on navigation or from a timer.

bts_signAndBroadcast sends the transaction to the chain. Label the button clearly as “broadcast” or “submit to the chain”, and keep it separate from “sign only”.

Confirm the network before using ids

A 1.2.x or 1.3.x id is not the same object on another network. Call bts_chainId first (and listen for chainChanged), then fill in account, asset, pool and order ids for that network.

Amounts are integer strings

Every amount is a decimal integer string (or an equivalent integer) in the asset's smallest unit. Do not pass floating-point numbers. With precision 5, 1.00000 BTS is "100000". Convert with BigInt or a decimal library in your app layer so you do not lose precision.

Use account ids; plaintext memos are fine

Operation account fields must be 1.2.x ids, not names. If your page talks to a node to resolve names, check the chain id and remind the user that the wallet approval window is authoritative.

For transfer-style memos you can pass a string and let the wallet encrypt it. Never ask the page for a memo private key.

Treat a lock and an empty account list correctly

After the wallet locks, bts_accounts returns []. That does not mean the user revoked the permission. Listen for lock and unlock, and query again after unlock. Query again after a network switch too.

Failures are a normal flow

The user rejecting the request, closing the window or letting it time out should be treated as cancel. Show error.message next to the action that started the request. Do not immediately re-open the approval window. 该站点已有待处理的请求 usually means a previous window is still open.

If you see 请求不存在或已过期, the extension background was probably discarded. Ask the user to click again.

Do not build the transaction envelope yourself

Send only operations. Let the wallet fill in the fee, the reference block and the transaction expiration. Stay within 10 operations and 3 proposal levels. Do not submit virtual operations.

Develop and ship on https

Outside of localhost, use https. The provider is not injected into iframes. Put staging on https or localhost, not on a plain http LAN address.