UniSat Wallet
UniSat Wallet API
Welcome to UniSat's Developer Documentation. This documentation is for learning to develop applications for UniSat Wallet.
Getting Started
To develop for UniSat Wallet, install UniSat Wallet on your development machine. Download here.
Once UniSat Wallet is installed and running, you should find that new browser tabs have a window.unisat
object available in the developer console. This is how your website will interact with UniSat Wallet.
Browser Detection
To verify if the browser is running UniSat Wallet, copy and paste the code snippet below in the developer console of your web browser:
You can review the full API for the window.unisat
object here.
Connecting to UniSat Wallet
"Connecting" or "logging in" to UniSat Wallet effectively means "to access the user's Bitcoin account(s)".
You should only initiate a connection request in response to direct user action, such as clicking a button. You should always disable the "connect" button while the connection request is pending. You should never initiate a connection request on page load.
We recommend that you provide a button to allow the user to connect UniSat Wallet to your dapp. Clicking this button should call the following method:
Demo
Methods
requestAccounts
Connect the current account.
Parameters
none
Returns
Promise
returns string[]
: Address of current account.
Example
getAccounts
Get address of current account
Parameters
none
Returns
Promise
-string
: address of current account
Example
getNetwork
get network
Please note that this method only supports bitcoin mainnet and bitcoin testnet. Due to the support for more networks, please switch to the getChain method.
Parameters
none
Returns
Promise
-string
: the network.livenet
andtestnet
Example
switchNetwork
switch network
Please note that this method only supports bitcoin mainnet and bitcoin testnet. Due to the support for more networks, please switch to the switchChain method.
Parameters
network
-string
: the network.livenet
andtestnet
Returns
none
Example
getChain
get chain
( Requires extension version greater than 1.4.0 )
Supported ChainsParameters
none
Returns
Promise
-Object
:enum
-string
: the enum of chainname
-string
: the name of chainnetwork
-string
:livenet
ortestnet
Example
switchChain
switch chain
( Requires extension version greater than 1.4.0 )
Parameters
chain
-string
: the chain.BITCOIN_MAINNET
orBITCOIN_TESTNET
orFRACTAL_BITCOIN_MAINNET
Returns
Promise
-Object
:enum
-string
: the enum of chainname
-string
: the name of chainnetwork
-string
:livenet
ortestnet
Example
getPublicKey
Get publicKey of current account.
Parameters
none
Returns
Promise
-string
: publicKey
Example
getBalance
Get BTC balance
Parameters
none
Returns
Promise
-Object
:confirmed
-number
: the confirmed satoshisunconfirmed
-number
: the unconfirmed satoshistotal
-number
: the total satoshis
Example
getInscriptions
List inscriptions of current account
Parameters
none
Returns
Promise
-Object
:total
-number
: the total countlist
-Object[]
:inscriptionId
-string
: the id of inscription.inscriptionNumber
-string
: the number of inscription.address
-string
: the address of inscription.outputValue
-string
: the output value of inscription.content
-string
: the content url of inscription.contentLength
-string
: the content length of inscription.contentType
-number
: the content type of inscription.preview
-number
: the preview linktimestamp
-number
: the blocktime of inscription.offset
-number
: the offset of inscription.genesisTransaction
-string
: the txid of genesis transactionlocation
-string
: the txid and vout of current location
Example
sendBitcoin
Send BTC
Parameters
toAddress
-string
: the address to sendsatoshis
-number
: the satoshis to sendoptions
-object
: (optional)feeRate
-number
: the network fee rate
Returns
Promise
-string
: txid
Example
sendRunes
Send Runes
Parameters
address
-string
: the receiver address.runeid
-string
: the runeidamount
-string
: the amount to sendoptions
-Object
: (optional)feeRate
-number
: the network fee rate
Returns
Promise
-Object
:txid
-string
: the txid
Example
sendInscription
Send Inscription
Parameters
address
-string
: the receiver address.inscriptionId
-string
: the id of Inscriptionoptions
-Object
: (optional)feeRate
-number
: the network fee rate
Returns
Promise
-Object
:txid
-string
: the txid
Example
inscribeTransfer
Inscribe BRC-20 TRANSFER Inscription
Parameters
ticker
-string
: BRC-20 tickeramount
-string
: the amount to inscribe
Returns
Promise
-void
:
Example
signMessage
sign message
Parameters
msg
-string
: a string to signtype
-string
: (Optional) "ecdsa" | "bip322-simple". default is "ecdsa"
Returns
Promise
-string
: the signature.
Example
pushTx
Push Transaction
Parameters
options
-Object
:rawtx
-string
: rawtx to push
Returns
Promise
-string
: txid
Example
signPsbt
Sign PSBT
This method will traverse all inputs that match the current address to sign.
Parameters
psbtHex
-string
: the hex string of psbt to signoptions
autoFinalized
-boolean
: whether finalize psbt after signing, default is truetoSignInputs
-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) Default value is false. Setting it true allows the use of the original private key when signing taproot inputs.useTweakedSigner
-boolean
:(optionals) . By setting useTweakedSigner, you can forcibly decide whether or not to use tweakedSigner. It has a higher priority than disableTweakSigner.
Returns
Promise
-string
: the hex string of signed psbt
Example
signPsbts
Sign Multiple PSBTs at once
This method will traverse all inputs that match the current address to sign.
Parameters
psbtHexs
-string[]
: the hex strings of psbt to signoptions
-object
[]: the options of signing psbtautoFinalized
-boolean
: whether finalize psbt after signing, default is truetoSignInputs
-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) sighashTypesuseTweakedSigner
-boolean
:(optionals) . By setting useTweakedSigner, you can forcibly decide whether or not to use tweakedSigner. It has a higher priority than disableTweakSigner.
Returns
Promise
-string[]
: the hex strings of signed psbt
Example
pushPsbt
Push transaction
Parameters
psbtHex
-string
: the hex string of psbt to push
Returns
Promise
-string
: txid
Example
Events
accountsChanged
The accountsChanged
will be emitted whenever the user's exposed account address changes.
networkChanged
The networkChanged
will be emitted whenever the user's network changes.
Last updated