下载

arrow_down

构建

arrow_down

更多

arrow_down
activityactivityactivityactivity
  • themelight
  • languageIcon

  • menu
Skip to Content

BTC

在 Bitget Wallet App 中运行 DApp 或在安装了 Chrome 扩展的 Chrome 浏览器中时,您可以访问全局对象window.bitkeep.unisat来进行后续的 API 调用。

const provider = window.bitkeep.unisat

版本

平台版本描述
Chrome Extension>=v2.1.1主网
App(IOS)>= 7.3.9主网
App(Android)>= 7.3.9主网
Note

注意 某些方法可能存在异常,将在新版本中得到支持。

平台版本功能
Chrome Extension>=v2.2.0getBalance, getInscriptions, pushTx
App(IOS)>= 8.8.0getBalance, getInscriptions, pushTx
App(Android)>= 8.8.0getBalance, getInscriptions, pushTx

连接Bitget钱包

请求连接到钱包

参数

返回值

  • Promise 返回 string[]:当前账户地址
try { let accounts = await unisat.requestAccounts(); console.log('connect success', accounts); } catch (e) { console.log('connect failed'); } > connect success ['tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz']

Account

getAccounts

获取当前账户地址

参数

返回值:

  • Promise - string:当前账户地址
try { let res = await unisat.getAccounts(); console.log(res) } catch (e) { console.log(e); } > ["tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz"]

查询公钥

获取当前用户的公钥

参数:

返回值:

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

查询余额

获取账户余额

参数:

返回值:

  • Promise - Object
    • confirmed - number:已确认的聪数
    • unconfirmed - number:未确认的聪数
    • total - number:总聪数
try { let res = await unisat.getBalance(); console.log(res) } catch (e) { console.log(e); } > { "confirmed":0, "unconfirmed":100000, "total":100000 }

网络

查询网络

参数

返回值

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

切换网络

参数

  • network - string:网络。livenet | testnet | signet

返回值

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

铭文

获取铭文

参数:

返回值:

  • Promise - Object
    • total - number:总数量
    • list - Object[]:
    • inscriptionId - string:铭文 ID
    • inscriptionNumber - string:铭文编号
    • address - string:铭文地址
    • outputValue - string:铭文输出值
    • content - string:铭文内容 URL
    • contentLength - string:铭文内容长度
    • contentType - number:铭文内容类型
    • preview - number:预览链接
    • timestamp - number:铭文区块时间
    • offset - number:铭文偏移量
    • genesisTransaction - string:创世交易 ID
    • location - string:当前位置
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 } ] }

发送铭文

参数:

  • address - string:接收者地址
  • inscriptionId - 铭文 ID
  • options - Object:(可选)
  • feeRate - number:网络手续费率

返回值:

  • Promise - Object:
    • txid - string:交易 ID
try { let { txid } = await unisat.sendInscription( 'tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny', 'e9b86a063d78cc8a1ed17d291703bcc95bcd521e087ab0c7f1621c9c607def1ai0', { feeRate: 15 } ) console.log( 'send Inscription 204 to tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny', { txid } ) } catch (e) { console.log(e) }

消息

签名

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
// sign by ecdsa try { let res = await provider.signMessage("abcdefghijk123456789"); console.log(res) } catch (e) { console.log(e); }

bip322-simple 签名

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

验证

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

交易

发送 BTC

参数:

  • toAddress - to:发送到的地址
  • satoshis - 发送的聪数
  • options - object:(可选)
    • feeRate - number:网络手续费率

返回值:

  • Promise - string:交易 ID
try { let txid = await unisat.sendBitcoin( 'tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz', 1000 ) console.log(txid) } catch (e) { console.log(e) }

广播交易

参数

  • options - Object:
    • rawtx - string:广播交易

返回值:

  • Promise - string:交易 ID
try { let txid = await unisat.pushTx({ rawtx: '0200000000010135bd7d...', }) console.log(txid) } catch (e) { console.log(e) }

签名 PSBT

此方法将遍历所有与当前地址匹配的输入进行签名。

参数:

  • psbtHex - string:要签名的 PSBT 的十六进制字符串。
  • options:object
    • autoFinalized - boolean:签名后是否完成 PSBT,默认为 true。
    • toSignInputs - array:
      • index - number:要签名的输入。
      • address - string:(至少指定地址或公钥)用于签名的对应私钥。
      • publicKey - string:(至少指定地址或公钥)用于签名的对应私钥。
      • sighashTypes - number[]:(可选)sighashTypes。
      • disableTweakSigner - boolean:(可选)默认情况下,在签名和解锁 Taproot 地址时使用 tweakSigner 生成签名。启用此选项允许使用原始私钥签名。

返回值:

  • Promise - string:已签名 PSBT 的十六进制字符串。
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) }

签名多个 PSBT

此方法将遍历所有与当前地址匹配的输入进行签名。

参数:

  • psbtHexs - string[]:要签名的 PSBT 的十六进制字符串。
  • options - object[]:签名 PSBT 的选项。
    • autoFinalized - boolean:签名后是否完成 PSBT,默认为 true。
    • toSignInputs - array:
      • index - number:要签名的输入。
      • address - string:(至少指定地址或公钥)用于签名的对应私钥。
      • publicKey - string:(至少指定地址或公钥)用于签名的对应私钥。
      • sighashTypes - number[]:(可选)sighashTypes。
      • disableTweakSigner - boolean:(可选)默认情况下,在签名和解锁 Taproot 地址时使用 tweakSigner 生成签名。启用此选项允许使用原始私钥签名。

返回值:

  • Promise - string[]:已签名 PSBT 的十六进制字符串。
try { let res = await unisat.signPsbts([ '70736274ff01007d...', '70736274ff01007d...', ]) console.log(res) } catch (e) { console.log(e) }

广播 PSBT

参数:

  • psbtHex - string:要广播的 PSBT 的十六进制字符串。

返回值:

  • Promise - string:交易 ID
try { let res = await unisat.pushPsbt('70736274ff01007d....') console.log(res) } catch (e) { console.log(e) }
Last updated on