Bitcoin Assets
The following provides several methods to list the wallet's assets and construct corresponding send transactions.
getBalance
window.bitpocket.unisat.getBalance()
Get BTC balance
Parameters
none
Returns
Promise-Object:available-number: the available satoshisunavailable-number: the unavailable satoshistotal-number: the total satoshis
Example
try {
let res = await window.bitpocket.unisat.getBalance();
console.log(res)
} catch (e) {
console.log(e);
}
> {"available":10000,"unavailable":546,"total":10546}
send BTC
window.bitpocket.unisat.openBtcPayForSignedPsbt(toAddress, amountInSats)
Send BTC
Parameters
toAddress-string: the address to sendamountInSats-number: the satoshis to send
Returns
Promise-string: signed psbt
Example
try {
let signedPsbt = await window.bitpocket.unisat.openBtcPayForSignedPsbt(
"tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz",
1000
);
console.log('signed psbt is ', signedPsbt);
//... you can call window.bitpocket.unisat.pushPsbt(signedPsbt, label) to publish this tx, or you can publish it by yourself
} catch (e) {
console.log(e);
}