Bitcoin Provider
Bitcoin Provider API
Provider Detection
// binancew3w.bitcoin
if (window.binancew3w.bitcoin) {
console.log('Bitcoin Provider is detected!');
}
// we also proxy window.unisat, but some of the APIs are different
if (window.unisat && window.unisat.isBinance) {
console.log('Bitcoin Provider is detected!');
}
Connecting to Bitcoin
Connecting" or "logging in" to Binance Web3 Wallet effectively means "to access the user's Bitcoin account(s)".
We recommend that you provide a button to allow the user to connect Binance Web3 Wallet to your dapp. Clicking this button should call the following method:
binancew3w.bitcoin.requestAccounts()
Methods
requestAccounts
binancew3w.bitcoin.requestAccounts()
Connect the current account.
Parameters
none
Returns
Promise
returns string[]
: Address of current account.
Example
try {
let accounts = await window.binancew3w.bitcoin.requestAccounts();
console.log('connect success', accounts);
} catch (e) {
console.log('connect failed');
}
> connect success ['tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz']
getAccounts
binancew3w.bitcoin.getAccounts()
Get address of current account
Parameters
none
Returns
Promise
returns string
: Address of current account.
Example
try {
let accounts = await window.binancew3w.bitcoin.getAccounts();
console.log('connect success', accounts);
} catch (e) {
console.log('connect failed');
}
> connect success ['tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz']
getNetwork
binancew3w.bitcoin.getNetwork()
Get network of current account
Parameters
none
Returns
Promise
returns string
: livenet
testnet
or signet
Example
try {
let accounts = await window.binancew3w.bitcoin.getNetwork();
console.log('connect network', accounts);
} catch (e) {
console.log('connect failed', e);
}
> 'livenet'