UniSat
  • home
    • UniSat Documentation Home
    • Production Roadmap
      • UniSat 2025 Q2 Work priorities
      • Overview of UniSat 2025 Work Priorities
      • Production Roadmap in Q4 2024
    • Assets potentially associated with UniSat's products
  • 🛠️dev
    • UniSat Developer Center
      • UniSat Wallet
        • Connect with UniSat Mobile Wallet
        • Supported Chains
      • Bitcoin
        • General
          • Blocks
            • Get Blockchain Info
            • Get Block Transactions
          • Transactions
            • Get Recommended Fees
            • Get Tx Info
            • Get Tx Inputs
            • Get Tx Outputs
            • Get UTXO Info
          • Addresses
            • Get Address Balance
            • Get Address History
            • Get BTC UTXO
            • Get Inscription UTXO
          • Inscriptions
            • Get Inscription Info
            • Get Inscription Content
            • Get Inscription Events
            • Get Address Inscriptions
        • BRC-20
          • Get Best Block Height
          • Get BRC-20 List
          • Get BRC-20 Status
          • Get BRC-20 Ticker Info
          • Get BRC-20 Holders
          • Get BRC-20 Ticker History
          • Get BRC-20 Total History By Height
          • Get BRC-20 Tx History
          • Get Address BRC-20 Summary
          • Get Address BRC-20 Ticker Info
          • Get Address BRC-20 History
          • Get Transferable Inscriptions
        • Runes
          • Get Runes Status
          • Get Runes Info List
          • Get Runes Info
          • Get Runes Holders
          • Get Address Runes Balance List
          • Get Address Runes Balance
          • Get UTXO Runes Balance
          • Get Address Runes UTXO
          • Get Runes Events
        • BRC20-Swap
          • Get Global Config
          • Get Address Balance
          • Get Deposit Info
          • Get Address All Ticker
          • Deploy Pool
          • Add Liq
          • Remove Liq
          • Swap
          • Get All Pool List
          • Get My Pool List
          • Get My Pool
          • Get Overview
          • Get Gas History
          • Get Liq History
          • Get Swap History
          • Get Rollup History
          • Get Deposit List
          • Deposit
          • Withdraw
          • Cancel Withdraw
          • Get Withdraw Process
          • Get Withdraw History
          • Get System Status
        • UniSat Inscribe
          • Get Order Summary
          • Get Order List
          • Create Order
          • Search Order
          • Refund estimate
          • Refund
          • Create BRC-20 DEPLOY
          • Create BRC-20 MINT
          • Create BRC-20 TRANSFER
        • UniSat Marketplace
          • BRC20 Marketplace
          • Runes Marketplace
          • Collection Marketplace
          • Domain Marketplace
        • UniSat Collection
          • Get Collection Status
          • Get Collection List
          • Get Collection Info
          • Get Collection Holders
          • Get Collection List By Address
          • Get Collection Items
          • Get Collection Summary By Address
          • Get Collection Items By Address
          • Get Collection List By Inscription
          • Add Items
          • Remove Items
        • UniSat Game Framework
      • API Demos
      • Fractal Bitcoin
        • General
          • Blocks
            • Get Blockchain Info
            • Get Block Transactions
          • Transactions
            • Get Tx Info
            • Get Tx Inputs
            • Get Tx Outputs
            • Get UTXO Info
          • Addresses
            • Get Address Balance
            • Get Address History
            • Get BTC UTXO
            • Get Inscription UTXO
          • Inscriptions
            • Get Inscription Info
            • Get Inscription Content
            • Get Inscription Events
            • Get Address Inscriptions
        • BRC-20
          • Get Best Block Height
          • Get BRC-20 List
          • Get BRC-20 Status
          • Get BRC-20 Ticker Info
          • Get BRC-20 Holders
          • Get BRC-20 Ticker History
          • Get BRC-20 Total History By Height
          • Get BRC-20 Tx History
          • Get Address BRC-20 Summary
          • Get Address BRC-20 Ticker Info
          • Get Address BRC-20 History
          • Get Transferable Inscriptions
        • Runes on Fractal
          • Get Runes Status
          • Get Runes Info List
          • Get Runes Info
          • Get Runes Holders
          • Get Address Runes Balance List
          • Get Address Runes Balance
          • Get UTXO Runes Balance
          • Get Address Runes UTXO
          • Get Runes Events
        • UniSat Inscribe on Fractal
          • Get Order Summary
          • Get Order List
          • Create Order
          • Search Order
          • Refund estimate
          • Refund
          • Create BRC-20 DEPLOY
          • Create BRC-20 MINT
          • Create BRC-20 TRANSFER
        • UniSat Marketplace on Fractal
          • BRC20 Marketplace
          • Runes Marketplace
          • Collection Marketplace
          • Domain Marketplace
        • UniSat Collection on Fractal
          • Get Collection Status
          • Get Collection List
          • Get Collection Info
          • Get Collection Holders
          • Get Collection List By Address
          • Get Collection Items
          • Get Collection Summary By Address
          • Get Collection Items By Address
          • Get Collection List By Inscription
          • Add Items
          • Remove Items
        • Get Fractal Circulating Supply
        • Get Fractal Total Supply
        • Get Fractal Total Address Count
        • Get Fractal Rich Address List
        • PizzaSwap
        • CAT Market
        • CAT20-DEX
          • Get Token Price
          • Get Market Stats
    • UniSat Developer Center Upgrading
      • Background of UniSat API Upgrading
      • How to Acquire a UniSat API Key
      • Enable the two-factor authentication
      • UniSat Developer Center Plans
      • FAQ
      • API Version Upgrade Notice: Untrack Deprecated brc20 Inscriptions
    • Developer Service Legal Disclaimer
    • Fractal Development Support (testnet)
  • 💡UniSat Services
    • UniSat Wallet
      • What is Signet?
      • UniSat Wallet FAQ
      • UniSat Wallet Address Type
      • Transfer brc-20 in UniSat Wallet
    • PizzaSwap
      • How to interact with PizzaSwap?
      • Green Channel User Guide
      • Guides for withdrawing your assets from PizzaSwap or brc20-swap
      • LPfest: Step-by-Step Guide
    • Single-Step Transfer
    • UniSat UTXO Management Tool
      • Understanding UTXO
      • How to unlock inscription/runes utxo and send as normal btc in utxo management.
    • Simple Bridge
      • How to use the Simple Bridge
    • Guides & Explanations
      • UniSat Titles Explained
      • UniSat Marketplace Fee Rates
      • UniSat Points Explained
      • FAQ
        • Drops FAQ
        • UTXO Management Tool FAQ
    • Product Chronicles
      • UniSat Wallet - Release Notes
        • v1.6.0
        • v1.5.8
        • v1.5.4
        • v1.5.2
        • v1.5.1
        • v1.4.10
        • v1.4.9
        • v1.4.6
        • v1.4.5
        • v1.4.2
        • v1.4.1
        • v1.4.0
        • v1.3.3
        • v1.3.2
        • v1.3.1
        • v1.3.0
        • v1.2.9
      • Timeline of brc-20 Swap and PizzaSwap Development
  • 💡Fractal Services
    • Fractal Service Links
    • FairPool
      • Getting Started with FairPool
    • Runes on Fractal
      • How to Etch Runes?
      • How to Mint Runes?
      • How to Trade Runes?
    • CAT Support
      • How to send / receive CAT20?
      • How to Buy and Sell CAT on UniSat CAT Market?
    • Full Node Configuration
    • Guides & Tutorials
      • How to Submit Collection in GitHub?
  • 📖Knowledge Base
    • Extension Wallet Safety Guide: Protecting Your Assets
      • Best Practices for Safety
    • Bitcoin Basics
      • What is Bitcoin?
      • How does Bitcoin work?
      • Understanding Bitcoin Address Types
      • Glossary
    • brc20-swap Introduction
      • What Is an Automated Market Maker?
      • Liquidity providers (LPs)
      • Testnet guide
      • Technical Q&A
      • Modules, withdrawals, and decentralization of brc-20
    • .unisat Names
    • Name recognized and resolved
    • Runes
      • How to Etch Runes?
      • How to Mint Runes?
      • How to Trade Runes?
  • 🎏Events & Collections
    • brc20-swap Early Access
    • UniSat OG Pass Collection
    • Other activities
      • Babylon Staking Activity
        • How to Transfer $BABY to a Cosmos Wallet
        • How to Participate in BTC Staking on Babylon Using UniSat Wallet
Powered by GitBook
On this page
  • UniSat Wallet API
  • Getting Started
  • Browser Detection
  • Connecting to UniSat Wallet
  • Demo
  • Methods
  • requestAccounts
  • getAccounts
  • getNetwork
  • switchNetwork
  • getChain
  • switchChain
  • getPublicKey
  • getBalance
  • getInscriptions
  • sendBitcoin
  • sendRunes
  • sendInscription
  • inscribeTransfer
  • signMessage
  • pushTx
  • signPsbt
  • signPsbts
  • pushPsbt
  • Events
  • accountsChanged
  • networkChanged
  1. dev
  2. UniSat Developer Center

UniSat Wallet

PreviousUniSat Developer CenterNextConnect with UniSat Mobile Wallet

Last updated 4 months ago

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

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:

unisat.requestAccounts()

Demo

Methods

requestAccounts

unisat.requestAccounts()

Connect the current account.

Parameters

none

Returns

Promise returns string[] : Address of current account.

Example

try {
  let accounts = await window.unisat.requestAccounts();
  console.log('connect success', accounts);
} catch (e) {
  console.log('connect failed');
}
> connect success ['tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz']

getAccounts

unisat.getAccounts()

Get address of current account

Parameters

none

Returns

  • Promise - string: address of current account

Example

try {
  let res = await window.unisat.getAccounts();
  console.log(res)
} catch (e) {
  console.log(e);
}
> ["tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz"]

getNetwork

unisat.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 and testnet

Example

try {
  let res = await window.unisat.getNetwork();
  console.log(res)
} catch (e) {
  console.log(e);
}

> 0

switchNetwork

unisat.switchNetwork(network)

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

try {
  let res = await window.unisat.switchNetwork("livenet");
  console.log(res)
} catch (e) {
  console.log(e);
}

> 0

getChain

unisat.getChain()

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

try {
  let res = await window.unisat.getChain();
  console.log(res)
} catch (e) {
  console.log(e);
}

>  {enum: 'BITCOIN_MAINNET', name: 'Bitcoin Mainnet', network: 'livenet'}

switchChain

unisat.switchChain(chain)

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

try {
  let res = await window.unisat.switchChain("BITCOIN_MAINNET");
  console.log(res)
} catch (e) {
  console.log(e);
}

> {enum: 'BITCOIN_MAINNET', name: 'Bitcoin Mainnet', network: 'livenet'}

getPublicKey

unisat.getPublicKey()

Get publicKey of current account.

Parameters

none

Returns

  • Promise - string: publicKey

Example

try {
  let res = await window.unisat.getPublicKey();
  console.log(res)
} catch (e) {
  console.log(e);
}
> 03cbaedc26f03fd3ba02fc936f338e980c9e2172c5e23128877ed46827e935296f

getBalance

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

try {
  let res = await window.unisat.getBalance();
  console.log(res)
} catch (e) {
  console.log(e);
}

> {
    "confirmed":0,
    "unconfirmed":100000,
    "total":100000
  }

getInscriptions

unisat.getInscriptions(cursor,size)

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

try {
  let res = await window.unisat.getInscriptions(0,10);
  console.log(res)
} catch (e) {
  console.log(e);
}

> {
  "total":10,
  "list":[
    {
      inscriptionId: '6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531i0',
      inscriptionNumber: 959941,
      address: 'bc1q8h8s4zd9y0lkrx334aqnj4ykqs220ss735a3gh',
      outputValue: 546,
      preview: 'https://ordinals.com/preview/6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531i0',
      content: 'https://ordinals.com/content/6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531i0',
      contentLength: 53,
      contentType: 'text/plain;charset=utf-8',
      timestamp: 1680865285,
      genesisTransaction: '6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531',
      location: '6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531:0:0',
      output: '6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531:0',
      offset: 0
    }
  ]
}

sendBitcoin

unisat.sendBitcoin(toAddress, satoshis, options)

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

try {
  let txid = await window.unisat.sendBitcoin("tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz",1000);
  console.log(txid)
} catch (e) {
  console.log(e);
}

sendRunes

unisat.sendRunes(address, runeid, amount, options)

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

try {
  let txid = await window.unisat.sendRunes("tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny","63104:1",10,{feeRate:15});
  console.log(txid)
} catch (e) {
  console.log(e);
}

sendInscription

unisat.sendInscription(address, inscriptionId, options)

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

try {
  let txid = await window.unisat.sendInscription("tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny","e9b86a063d78cc8a1ed17d291703bcc95bcd521e087ab0c7f1621c9c607def1ai0",{feeRate:15});
  console.log("send Inscription 204 to tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny",txid)
} catch (e) {
  console.log(e);
}

inscribeTransfer

unisat.inscribeTransfer(ticker, amount)

Inscribe BRC-20 TRANSFER Inscription

Parameters

  • ticker - string: BRC-20 ticker

  • amount - string: the amount to inscribe

Returns

  • Promise - void:

Example


window.unisat.inscribeTransfer("ordi","100"); 

signMessage

unisat.signMessage(msg[, type])

sign message

Parameters

  • msg - string: a string to sign

  • type - string: (Optional) "ecdsa" | "bip322-simple". default is "ecdsa"

Returns

  • Promise - string: the signature.

Example

// sign by ecdsa
try {
  let res = await window.unisat.signMessage("abcdefghijk123456789");
  console.log(res)
} catch (e) {
  console.log(e);
}

> G+LrYa7T5dUMDgQduAErw+i6ebK4GqTXYVWIDM+snYk7Yc6LdPitmaqM6j+iJOeID1CsMXOJFpVopvPiHBdulkE=

// verify by ecdsa
import { verifyMessage } from "@unisat/wallet-utils";
const pubkey = "026887958bcc4cb6f8c04ea49260f0d10e312c41baf485252953b14724db552aac";
const message = "abcdefghijk123456789";
const signature = "G+LrYa7T5dUMDgQduAErw+i6ebK4GqTXYVWIDM+snYk7Yc6LdPitmaqM6j+iJOeID1CsMXOJFpVopvPiHBdulkE=";
const result = verifyMessage(pubkey,message,signature);
console.log(result);

> true


// sign by bip322-simple
try {
  let res = await window.unisat.signMessage("abcdefghijk123456789","bip322-simple");
  console.log(res)
} catch (e) {
  console.log(e);
}

> AkcwRAIgeHUcjr0jODaR7GMM8cenWnIj0MYdGmmrpGyMoryNSkgCICzVXWrLIKKp5cFtaCTErY7FGNXTFe6kuEofl4G+Vi5wASECaIeVi8xMtvjATqSSYPDRDjEsQbr0hSUpU7FHJNtVKqw=

pushTx

unisat.pushTx(options)

Push Transaction

Parameters

  • options - Object:

    • rawtx - string: rawtx to push

Returns

  • Promise - string: txid

Example

try {
  let txid = await window.unisat.pushTx({
    rawtx:"0200000000010135bd7d..."
  });
  console.log(txid)
} catch (e) {
  console.log(e);
}

signPsbt

unisat.signPsbt(psbtHex[, options])

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

try {
  let res = await window.unisat.signPsbt(
    "70736274ff01007d....",
    {
        autoFinalized:false,
        toSignInputs:[
          {
            index: 0,
            address: "tb1q8h8....mjxzny",
          },
          {
            index: 1,
            publicKey: "tb1q8h8....mjxzny",
            sighashTypes: [1]
          },
          {
            index: 2,
            publicKey: "02062...8779693f",
          }
        ]
    }
  );
  console.log(res)
} catch (e) {
  console.log(e);
}

unisat.signPsbt("xxxxxxxx",{toSignInputs:[{index:0,publicKey:"xxxxxx",disableTweakSigner:true}],autoFinalized:false})

signPsbts

unisat.signPsbts(psbtHexs[, options])

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

try {
  let res = await window.unisat.signPsbts(["70736274ff01007d...","70736274ff01007d..."]);
  console.log(res)
} catch (e) {
  console.log(e);
}

pushPsbt

unisat.pushPsbt(psbtHex)

Push transaction

Parameters

  • psbtHex - string: the hex string of psbt to push

Returns

  • Promise - string: txid

Example

try {
  let res = await window.unisat.pushPsbt("70736274ff01007d....");
  console.log(res)
} catch (e) {
  console.log(e);
}

Events

accountsChanged

unisat.on('accountsChanged', handler: (accounts: Array<string>) => void);
unisat.removeListener('accountsChanged', handler: (accounts: Array<string>) => void);

The accountsChanged will be emitted whenever the user's exposed account address changes.

networkChanged

unisat.on('networkChanged', handler: (network: string) => void);
unisat.removeListener('networkChanged', handler: (network: string) => void);

The networkChanged will be emitted whenever the user's network changes.

🛠️
Download here
Online Demo
Demo source code
Supported Chains