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:

if (typeof window.unisat !== 'undefined') {
  console.log('UniSat Wallet is installed!');
}

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

Parameters

none

Returns

  • Promise - string: the network. livenet and testnet

Example

switchNetwork

switch network

Parameters

  • network - string: the network. livenet and testnet

Returns

none

Example

getChain

get chain

( Requires extension version greater than 1.4.0 )

Supported Chains

Parameters

none

Returns

  • Promise - Object:

    • enum - string : the enum of chain

    • name - string : the name of chain

    • network - string : livenet or testnet

Example

switchChain

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

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 satoshis

    • unconfirmed - number : the unconfirmed satoshis

    • total - number : the total satoshis

Example

getInscriptions

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

sendBitcoin

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

sendRunes

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

sendInscription

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

inscribeTransfer

Inscribe BRC-20 TRANSFER Inscription

Parameters

  • ticker - string: BRC-20 ticker

  • amount - string: the amount to inscribe

Returns

  • Promise - void:

Example

signMessage

sign message

Parameters

  • msg - string: a string to sign

  • type - 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 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

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 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

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