UniSat Wallet
Last updated
Last updated
Welcome to UniSat's Developer Documentation. This documentation is for learning to develop applications for UniSat Wallet.
To develop for UniSat Wallet, install UniSat Wallet on your development machine. .
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.
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" 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:
Connect the current account.
Parameters
none
Returns
Promise
returns string[]
: Address of current account.
Example
Get address of current account
Parameters
none
Returns
Promise
- string
: address of current account
Example
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
and testnet
Example
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
and testnet
Returns
none
Example
get chain
( Requires extension version greater than 1.4.0 )
Parameters
none
Returns
Promise
- Object
:
enum
- string
: the enum of chain
name
- string
: the name of chain
network
- string
: livenet
or testnet
Example
switch chain
( Requires extension version greater than 1.4.0 )
Parameters
chain
- string
: the chain. BITCOIN_MAINNET
or BITCOIN_TESTNET
or FRACTAL_BITCOIN_MAINNET
Returns
Promise
- Object
:
enum
- string
: the enum of chain
name
- string
: the name of chain
network
- string
: livenet
or testnet
Example
Get publicKey of current account.
Parameters
none
Returns
Promise
- string
: publicKey
Example
Get BTC balance
Parameters
none
Returns
Promise
- Object
:
confirmed
- number
: the confirmed satoshis
unconfirmed
- number
: the unconfirmed satoshis
total
- number
: the total satoshis
Example
List inscriptions of current account
Parameters
none
Returns
Promise
- Object
:
total
- number
: the total count
list
- 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 link
timestamp
- number
: the blocktime of inscription.
offset
- number
: the offset of inscription.
genesisTransaction
- string
: the txid of genesis transaction
location
- string
: the txid and vout of current location
Example
Send BTC
Parameters
toAddress
- string
: the address to send
satoshis
- number
: the satoshis to send
options
- object
: (optional)
feeRate
- number
: the network fee rate
memo
- string
: (optional) The data content of OP_RETURN, which needs to be in UTF-8 or HEX encoded format.
memos
- string[]
: (optional) The data content of OP_RETURN, which needs to be in UTF-8 or HEX encoded format, provided in the form of an array.
Returns
Promise
- string
: txid
Example
Send Runes
Parameters
address
- string
: the receiver address.
runeid
- string
: the runeid
amount
- string
: the amount to send
options
- Object
: (optional)
feeRate
- number
: the network fee rate
Returns
Promise
- Object
:
txid
- string
: the txid
Example
Send Inscription
Parameters
address
- string
: the receiver address.
inscriptionId
- string
: the id of Inscription
options
- Object
: (optional)
feeRate
- number
: the network fee rate
Returns
Promise
- Object
:
txid
- string
: the txid
Example
Inscribe BRC-20 TRANSFER Inscription
Parameters
ticker
- string
: BRC-20 ticker
amount
- string
: the amount to inscribe
Returns
Promise
- void
:
Example
sign message
Parameters
msg
- string
: a string to sign
type
- string
: (Optional) "ecdsa" | "bip322-simple". default is "ecdsa"
Returns
Promise
- string
: the signature.
Example
Push Transaction
Parameters
options
- Object
:
rawtx
- string
: rawtx to push
Returns
Promise
- string
: txid
Example
Sign PSBT
This method will traverse all inputs that match the current address to sign.
Parameters
psbtHex
- string
: the hex string of psbt to sign
options
autoFinalized
- boolean
: whether finalize psbt after signing, default is true
toSignInputs
- array
:
index
- number
: which input to sign
address
- string
: (at least specify either an address or a publicKey) Which corresponding private key to use for signing
publicKey
- string
: (at least specify either an address or a publicKey) Which corresponding private key to use for signing
sighashTypes
- number[]
: (optionals) sighashTypes
disableTweakSigner
- 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
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 sign
options
- object
[]: the options of signing psbt
autoFinalized
- boolean
: whether finalize psbt after signing, default is true
toSignInputs
- array
:
index
- number
: which input to sign
address
- string
: (at least specify either an address or a publicKey) Which corresponding private key to use for signing
publicKey
- string
: (at least specify either an address or a publicKey) Which corresponding private key to use for signing
sighashTypes
- number[]
: (optionals) sighashTypes
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 strings of signed psbt
Example
Push transaction
Parameters
psbtHex
- string
: the hex string of psbt to push
Returns
Promise
- string
: txid
Example
The accountsChanged
will be emitted whenever the user's exposed account address changes.
The networkChanged
will be emitted whenever the user's network changes.