Skip to content

BTC

When running a DApp in the Bitget Wallet App or in the Chrome browser with the Chrome Extension installed, you can access the global object window.bitkeep.unisat for subsequent API calls.

js
const provider = window.bitkeep.unisat
const provider = window.bitkeep.unisat

Bitget Wallet only supports this feature in the following versions:

PlatformVersionDescription
Chrome Extension>=v2.1.1mainnet
App(IOS)>= 7.3.9mainnet
App(Android)>= 7.3.9mainnet

Note

Some methods may have exceptions and will be supported in new versions.

PlatformVersionfunction
Chrome Extension>=v2.2.0getBalance, getInscriptions, pushTx
App(IOS)>= 8.8.0getBalance, getInscriptions, pushTx
App(Android)>= 8.8.0getBalance, getInscriptions, pushTx

requestAccounts

Request to Connect to Wallet

Parameters:

  • none

Return Value:

  • Promise returns string[]: Current account address
js
try {
  let accounts = await unisat.requestAccounts();
  console.log('connect success', accounts);
} catch (e) {
  console.log('connect failed');
}
> connect success ['tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz']
try {
  let accounts = await unisat.requestAccounts();
  console.log('connect success', accounts);
} catch (e) {
  console.log('connect failed');
}
> connect success ['tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz']

getAccounts

Get Current Account Address

Parameters:

  • none

Returns:

  • Promise - string: Current account address
js
try {
  let res = await unisat.getAccounts();
  console.log(res)
} catch (e) {
  console.log(e);
}
> ["tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz"]
try {
  let res = await unisat.getAccounts();
  console.log(res)
} catch (e) {
  console.log(e);
}
> ["tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz"]

getNetwork

Get Current Network

Parameters:

  • none

Returns:

  • Promise - string: the network. livenet | testnet | signet
js
try {
  let res = await unisat.getNetwork();
  console.log(res)
} catch (e) {
  console.log(e);
}
> 'livenet'
try {
  let res = await unisat.getNetwork();
  console.log(res)
} catch (e) {
  console.log(e);
}
> 'livenet'

switchNetwork

Switch Network

Parameters:

  • network - string: the network. livenet | testnet | signet

Returns

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

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

> 'livenet'

getPublicKey

Get Current User's Public Key

Parameters:

  • none

Returns:

  • Promise - string: publicKey
js
try {
  let res = await unisat.getPublicKey();
  console.log(res)
} catch (e) {
  console.log(e);
}
> "03cbaedc26f03fd3ba02fc936f338e980c9e2172c5e23128877ed46827e935296f"
try {
  let res = await unisat.getPublicKey();
  console.log(res)
} catch (e) {
  console.log(e);
}
> "03cbaedc26f03fd3ba02fc936f338e980c9e2172c5e23128877ed46827e935296f"

getBalance

Get Account Balance

Parameters:

  • none

Returns:

  • Promise - Object
    • confirmed - number : the confirmed satoshis
    • unconfirmed - numbet: the unconfirmed satoshis
    • total - number: the total satoshis
js
try {
  let res = await unisat.getBalance();
  console.log(res)
} catch (e) {
  console.log(e);
}

> {
    "confirmed":0,
    "unconfirmed":100000,
    "total":100000
  }
try {
  let res = await unisat.getBalance();
  console.log(res)
} catch (e) {
  console.log(e);
}

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

getInscriptions

Get Current Account's Inscriptions

Parameters:

  • none

Returns:

  • Promise - Object
    • total - number : Total count
    • list - Object[] :
    • inscriptionId - string : Inscription ID
    • inscriptionNumber - string : Inscription Number
    • address - string : Inscription Address
    • outputValue - string : Inscription Output Value
    • content - string : Inscription Content URL
    • contentLength - string : Inscription Content Length
    • contentType - number : Inscription Content Type
    • preview - number : Preview link
    • timestamp - number : Inscription Block Time
    • offset - number : Inscription Offset
    • genesisTransaction - string : Genesis Transaction ID
    • location - string : Current Location
js
try {
  let res = await 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
    }
  ]
}
try {
  let res = await 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

Send BTC

Parameters:

  • toAddress - to: Address to send
  • satoshis - Amount of Satoshis Sent
  • options - object: (optional)
    • feeRate - number: Network Fee Rate

Returns:

  • Promise - string: Transaction id
js
try {
  let txid = await unisat.sendBitcoin("tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz",1000);
  console.log(txid)
} catch (e) {
  console.log(e);
}
try {
  let txid = await unisat.sendBitcoin("tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz",1000);
  console.log(txid)
} catch (e) {
  console.log(e);
}

sendInscription

Send Inscription

Parameters:

  • address - string: Recipient Address
  • inscriptionId - Inscription id
  • options - Object: (optional)
  • feeRate - number: Network Fee Rate

Returns:

  • Promise - Object:
    • txid - string : the txid
js
try {
  let { txid } = await unisat.sendInscription("tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny","e9b86a063d78cc8a1ed17d291703bcc95bcd521e087ab0c7f1621c9c607def1ai0",{feeRate:15});
  console.log("send Inscription 204 to tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny",{txid})
} catch (e) {
  console.log(e);
}
try {
  let { txid } = await unisat.sendInscription("tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny","e9b86a063d78cc8a1ed17d291703bcc95bcd521e087ab0c7f1621c9c607def1ai0",{feeRate:15});
  console.log("send Inscription 204 to tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny",{txid})
} catch (e) {
  console.log(e);
}

signMessage

sign message

Parameters:

  • msg - string: String to be Signed
  • type - string: (Optional) "ecdsa" | "bip322-simple". default is "ecdsa". Optional Parameters for Signing

Returns:

  • Promise - string: Signature Result
js
// sign by ecdsa
try {
  let res = await provider.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=
// sign by ecdsa
try {
  let res = await provider.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

Push Transaction

Parameters

  • options - Object:
    • rawtx - string: Broadcast Transaction

Returns:

  • Promise - string: the txid
js
try {
  let txid = await unisat.pushTx({
    rawtx:"0200000000010135bd7d..."
  });
  console.log(txid)
} catch (e) {
  console.log(e);
}
try {
  let txid = await unisat.pushTx({
    rawtx:"0200000000010135bd7d..."
  });
  console.log(txid)
} catch (e) {
  console.log(e);
}

signPsbt

Sign PSBT This method will iterate through all inputs that match the current address for signing.

Parameters:

  • psbtHex - string: Hexadecimal string of the PSBT to be signed.
  • options: object
    • autoFinalized - boolean: Whether to finalize the PSBT after signing, default is true.
    • toSignInputs - array:
      • index - number: Which input to sign.
      • address - string: (Specify at least address or public key) Corresponding private key used for signing.
      • publicKey - string: (Specify at least address or public key) Corresponding private key used for signing.
      • sighashTypes - number[]: (Optional) sighashTypes.
      • disableTweakSigner - boolean: (Optional) By default, tweakSigner is used to generate signatures when signing and unlocking Taproot addresses. Enabling this option allows signing with the raw private key.

Returns:

  • Promise - string: Hexadecimal string of the signed PSBT.
js
try {
  let res = await 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);
}
try {
  let res = await 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);
}

signPsbts

Sign Multiple PSBTs at once This method will iterate through all inputs that match the current address for signing.

Parameters:

  • psbtHexs - string[]: Hexadecimal strings of the PSBTs to be signed.
  • options - object[]: Options for signing the PSBTs.
    • autoFinalized - boolean: Whether to finalize the PSBT after signing, default is true.
    • toSignInputs - array:
      • index - number: Which input to sign.
      • address - string: (Specify at least address or public key) Corresponding private key used for signing.
      • publicKey - string: (Specify at least address or public key) Corresponding private key used for signing.
      • sighashTypes - number[]: (Optional) sighashTypes.
      • disableTweakSigner - boolean: (Optional) By default, tweakSigner is used to generate signatures when signing and unlocking Taproot addresses. Enabling this option allows signing with the raw private key.

Returns:

  • Promise - string[]: Hexadecimal strings of the signed PSBTs.
js
try {
  let res = await unisat.signPsbts(["70736274ff01007d...","70736274ff01007d..."]);
  console.log(res)
} catch (e) {
  console.log(e);
}
try {
  let res = await unisat.signPsbts(["70736274ff01007d...","70736274ff01007d..."]);
  console.log(res)
} catch (e) {
  console.log(e);
}

pushPsbt

Broadcast PSBT

Parameters:

  • psbtHex - string: Hexadecimal string of the PSBT to be broadcasted.

Returns:

  • Promise - string: Transaction ID
js
try {
  let res = await unisat.pushPsbt("70736274ff01007d....");
  console.log(res)
} catch (e) {
  console.log(e);
}
try {
  let res = await unisat.pushPsbt("70736274ff01007d....");
  console.log(res)
} catch (e) {
  console.log(e);
}