方法

requestAccounts

获取当前账户

请求

cactuslink.requestAccounts()

参数

返回

  • Promise - string[]: 当前账户的地址

示例

try {
    let accounts = await window.cactuslink.requestAccounts();
    console.log('connected to', accounts);
} catch (e) {
    console.log('connection failed');
}

> connected to ['1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1']

getAccounts

获取当前账户的地址

请求

cactuslink.getAccounts()

参数

返回

  • Promise - string[]: 当前账户的地址

示例

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

> ['1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1']

getNetwork

获取当前账户所属网络

请求

cactuslink.getNetwork()

参数

返回

  • Promise - string: 网络类型,包含 mainnet, signettestnet

示例

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

> 0

switchNetwork

switch the network

请求

cactuslink.switchNetwork(network)

参数

  • network - string: 待切换的网络, 包含 mainnet, signettestnet

返回

示例

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

> 0

getPublicKey

获取当前账户的公钥

请求

cactuslink.getPublicKey()

参数

返回

  • Promise - string: 公钥

示例

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

> 03cbaedc26f03fd3ba02fc936f338e980c9e2172c5e23128877ed46827e935296f

getBalance

获取当前账户 BTC 余额

请求

cactuslink.getBalance()

参数

返回

  • Promise - Object:
    • confirmed - number: 已确认的聪数量
    • unconfirmed - number: 待确认的聪数量
    • total - number: 总的聪数量

示例

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

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

getBitcoinUtxos

获取当前账户的UTXO

请求

cactuslink.getBitcoinUtxos(cursor,size)

参数

  • cursor - number: (可选) 偏移量、从 0 开始,默认值 0
  • size - number: (可选) 每页数量,默认值 20

返回

  • Promise - Object:
    • txid - string: 交易哈希
    • vout - number: 当前输出的索引序号
    • satoshis - number: 输出金额
    • srciptPk - string: 关联的锁定脚本
    • adressType - number: 0代表 Native Segwit (P2WPKH), 2代表 Taproot (P2TR)
    • pubkey - string: 输出关联的公钥,用于验证签名

示例

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

> [{
    "txid": "05c467f65af589dc0636a31f52093a1afa3940ce509c13ad3390ecfb4c710b05",
    "vout": 1,
    "satoshis": 5554937,
    "scriptPk": "0014144ce0ac011060e140fc0a2202e94b59afe71f80",
    "addressType": 1,
    "pubkey": "02c7ac587ec0024b0bc78c2aea04a1339f0d4038e712b8516215879989d574aea9"
  }]

signMessage

通过签名消息验证持有者

请求

cactuslink.signMessage(msg[, type])

参数

  • msg - string:待签名字符
  • type - string: (可选) "ecdsa" (其他类型暂未支持如bip322-simple)

返回

Promise - string: the signature

示例

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

> G+LrYa7T5dUMDgQduAErw+i6ebK4GqTXYVWIDM+snYk7Yc6LdPitmaqM6j+iJOeID1CsMXOJFpVopvPiHBdulkE=

pushTx

发送交易

请求

cactuslink.pushTx(options)

参数

  • options - Object:
    • rawtx - string: 待发送的原始交易

返回

  • Promise - string: txid

示例

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

signPsbt

遍历当前地址涉及的输入信息并签名

请求

cactuslink.signPsbt(psbtHex[, options])

参数

  • psbtHex - string: 待签名的 PSBT 十六进制字符
  • options *autoFinalized - boolean: 签名后是否完成 PSBT,默认 true

返回

  • Promise - string: 已签名的 PSBT 十六进制字符

示例

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

cactuslink.signPsbt("xxxxxxxx", {autoFinalized:false})

pushPsbt

发送 PSBT 交易

请求

cactuslink.pushPsbt(psbtHex)

参数

  • psbtHex - string: PSBT 十六进制字符

返回

  • Promise - string: txid

示例

try {
  let res = await window.cactuslink.pushPsbt("70736274ff01007d....");
  console.log(res)
} catch (e) {
  console.log(e);
}
Copyright © 2025 Cactus Custody all right reserved,powered by GitbookUpdated: 10-Sep-2025 03:20:52

results matching ""

    No results matching ""

    results matching ""

      No results matching ""