Bitcoin Provider API
TokenPocket Extension injects a Bitcoin Provider into the page and is compatible with common UniSat-style APIs. Developers can use familiar Bitcoin dApp methods for account access, message signing, PSBT signing, and broadcasting.
Provider Injection
The following objects are available on the page:
window.unisat
window.tokenpocket.bitcoinNotes:
window.unisat: UniSat-compatible entry pointwindow.tokenpocket.bitcoin: Native TokenPocket Bitcoin Provider
After initialization, the page dispatches:
window.dispatchEvent(new Event('unisat#initialized'));Quick Start
Request Accounts
const accounts = await window.unisat.requestAccounts();
console.log(accounts[0]);Get Public Key
Sign a Message
API List
requestAccounts
Requests connection for the current site and returns the BTC address list.
Example:
getAccounts
Returns the BTC address list already authorized for the current site.
getPublicKey
Returns the public key for the active BTC address.
getBalance
Returns BTC balance information.
Notes:
The exact response shape follows the wallet implementation.
getNetwork
Returns the current network identifier.
Current version only supports:
getChain
Returns the current chain information.
Current version returns mainnet information:
getVersion
Returns the Provider version.
switchNetwork
Switches network.
Notes:
Current version only allows mainnet.
switchChain
Switches chain configuration.
Notes:
Current version only allows mainnet.
signMessage
Signs a message.
Example:
signPsbt
Signs a single PSBT.
signPsbts
Signs multiple PSBTs.
pushPsbt
Finalizes and broadcasts a PSBT.
pushTx
Broadcasts a raw transaction.
sendBitcoin
Sends BTC.
Example:
Events
The Bitcoin Provider supports event listeners.
accountsChanged
Triggered when the active address changes.
networkChanged
Triggered when the network changes.
Event Methods
Supported listener methods:
ononceoffaddListenerremoveListenerremoveAllListeners
Error Handling
Use try/catch for all Provider calls.
Common failure cases:
User rejects the connection request.
User rejects signing or transaction confirmation.
The current site is not authorized.
No BTC address is available.
The requested network is not supported.
Compatibility Notes
TokenPocket exposes both
window.unisatandwindow.tokenpocket.bitcoin.The API shape is designed to be compatible with common UniSat integrations.
The current version only supports Bitcoin Mainnet.