Bitcoin L1

Bitcoin L1 specific methods

Methods

getBalance

zky.getBalance()

Get BTC balance.

Parameters

None

Returns

  • Promise - Object:

    • confirmed - number: the confirmed satoshis.

    • unconfirmed - number: the unconfirmed satoshis.

    • total - number: the total satohis.

Example

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

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

getInscriptions

zky.getInscriptions(cursor, size)

List inscriptions of current account.

Parameters

  • cursor - number

  • size - number

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

zky.sendBitcoin(toAddress, satoshis, options)

Send BTC over Bitcoin L1.

Parameters

  • toAddress - string: the address to send.

  • satoshis - number: the satoshis to send.

  • options - object: (optional)

    • feeRate - number: the network fee rate.

Returns

  • Promise - string: txid

Example

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

sendInscription

zky.sendInscription(address, inscriptionId, options)

Send Inscription over Bitcoin L1.

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.zky.sendInscription("tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny","e9b86a063d78cc8a1ed17d291703bcc95bcd521e087ab0c7f1621c9c607def1ai0",{feeRate:15});
  console.log("send Inscription 204 to tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny",{txid})
} catch (e) {
  console.log(e);
}

inscribeTransfer

zky.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.zky.inscribeTransfer("ordi","100"); 

pushTx

zky.pushTx(options)

Push Transaction.

Parameters

  • options - Object:

    • rawtx - string: rawtx to push.

Returns

  • Promise - string: txid.

Example

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

signPsbt

zky.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[]: (optional) sighashTypes.

      • disableTweakSigner - boolean :(optionals) When signing and unlocking Taproot addresses, the tweakSigner is used by default for signature generation. Enabling this allows for signing with the original private key.

Returns

  • Promise - string: the hex string of signed psbt.

Example

try {
  let res = await window.zky.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);
}

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

signPsbts

zky.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[]: (optional) sighashTypes.

Returns

  • Promise - string[]: the hex strings of signed psbt.

Example

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

pushPsbt

zky.pushPsbt(psbtHex)

Push transaction.

Parameters

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

Returns

  • Promise - string: txid.

Example

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

Last updated