Bitcoin Provider
#
Bitcoin Provider API#
Provider Detection#
Connecting to BitcoinConnecting" 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:
#
Methods#
requestAccountsConnect the current account.
#
Parametersnone
#
ReturnsPromise
returns string[]
: Address of current account.
#
Example#
getAccountsGet address of current account
#
Parametersnone
#
ReturnsPromise
returns string
: Address of current account.
#
Example#
getNetworkGet network of current account
#
Parametersnone
#
ReturnsPromise
returns string
: livenet
testnet
or signet
#
Example#
switchNetworkSwitch network
#
Parametersnetwork
-string
: the network.livenet
testnet
orsignet
#
Returnsnone
#
Example#
getPublicKeyGet publicKey of current account
#
Parametersnone
#
ReturnsPromise
returns string
: publicKey (no tweak for taproot)
#
Example#
getBalanceGet BTC balance
#
Parametersnone
#
ReturnsPromise
returnsObject
:confirmed
-number
: the confirmed satoshisunconfirmed
-number
: the unconfirmed satoshistotal
-number
: the total satoshis
#
Example#
signMessagesign message
#
Parametersmsg
-string
: a string to signtype
-string
: (Optional) "ecdsa" | "bip322-simple". default is "ecdsa"
#
ReturnsPromise
returnsstring
: the signature
#
Example#
signPsbtSign PSBT
This method will traverse all inputs that match the current address to sign.
#
ParameterspsbtHex
-string
: the hex string of psbt to signoptions
-object
:autoFinalized
-boolean
: whether finalize inputs signed by user's wallet after signing, default istrue
toSignInputs
-array
:index
-number
: which input to signaddress
-string
: (at least specify either an address or a publicKey) Which corresponding private key to use for signingpublicKey
-string
: (at least specify either an address or a publicKey) Which corresponding private key to use for signingsighashTypes
-number[]
: (optionals) sighashTypesdisableTweakSigner
-boolean
: (optionals) When signing and unlocking Taproot addresses, the tweakSigner is used by default for signature generation. Enabling this allows for signing with the original private key.
#
ReturnsPromise
returnsstring
: the hex string of signed psbt
#
Example#
Events#
accountsChangedThe accountsChanged will be emitted whenever the user's exposed account address changes.
#
networkChangedThe networkChanged will be emitted whenever the user's network changes.