javascript – How one can construct a transaction utilizing bitcoinjs-lib

0
66


I am attempting to construct a transaction utilizing bitcoinjs-lib.

Right here is my final transaction.
https://blockstream.information/api/tx/91feea5f5c7b67b3e56c0f5d23d6da3065855c23b4cc7dded8efd8ff8065500f

{
  "weight" : 705,
  "txid" : "91feea5f5c7b67b3e56c0f5d23d6da3065855c23b4cc7dded8efd8ff8065500f",
  "standing" : {
    "block_height" : 795582,
    "block_hash" : "00000000000000000005386018b10cd1cde59d6923fd918757690c004b01c4b8",
    "confirmed" : true,
    "block_time" : 1687529469
  },
  "vin" : [
    {
      "inner_redeemscript_asm" : "OP_0 OP_PUSHBYTES_20 01868bd1fb92e6547438e8bf07a6c08ee0157c8b",
      "txid" : "e0c545a6dfaf1d5bb67f6349190d0653b597bda6585696cf217e55df07b1f190",
      "prevout" : {
        "scriptpubkey_type" : "p2sh",
        "scriptpubkey_address" : "3PA2J9aN9N82q4YZyhBYHBcHpVvpGewvX2",
        "value" : 956656,
        "scriptpubkey_asm" : "OP_HASH160 OP_PUSHBYTES_20 eb762ef1946c2d462764d30112ce27c531fdd603 OP_EQUAL",
        "scriptpubkey" : "a914eb762ef1946c2d462764d30112ce27c531fdd60387"
      },
      "scriptsig_asm" : "OP_PUSHBYTES_22 001401868bd1fb92e6547438e8bf07a6c08ee0157c8b",
      "is_coinbase" : false,
      "vout" : 1,
      "sequence" : 4294967295,
      "witness" : [
        "304402206000ff05c68afd2b2aece9554ef25bae6d7402be96c6eedc866f4ca1dcafe0dd02204dfc8852bd4c4ae2f36cd0f4db82d22e37422b08e7d829f10e5aa9d8ae07d70901",
        "02dba3c42f38c394dd7370884f23bd0dec5373e9d38439915124188f06b6a19395"
      ],
      "scriptsig" : "16001401868bd1fb92e6547438e8bf07a6c08ee0157c8b"
    }
  ],
  "vout" : [
    {
      "scriptpubkey_type" : "v1_p2tr",
      "scriptpubkey_address" : "bc1p7cqr7rhvxy8c69k5ks3qp6h3nq85tskgxd4f0h0mz5g3lvtykgtq4ddhyc",
      "value" : 54980,
      "scriptpubkey_asm" : "OP_PUSHNUM_1 OP_PUSHBYTES_32 f6003f0eec310f8d16d4b42200eaf1980f45c2c8336a97ddfb15111fb164b216",
      "scriptpubkey" : "5120f6003f0eec310f8d16d4b42200eaf1980f45c2c8336a97ddfb15111fb164b216"
    },
    {
      "scriptpubkey_type" : "p2sh",
      "scriptpubkey_address" : "3PA2J9aN9N82q4YZyhBYHBcHpVvpGewvX2",
      "value" : 894242,
      "scriptpubkey_asm" : "OP_HASH160 OP_PUSHBYTES_20 eb762ef1946c2d462764d30112ce27c531fdd603 OP_EQUAL",
      "scriptpubkey" : "a914eb762ef1946c2d462764d30112ce27c531fdd60387"
    }
  ],
  "dimension" : 258,
  "locktime" : 0,
  "model" : 2,
  "payment" : 7434
}

Right here is the code I am engaged on. What do I exploit for the redeem script?

const community = bitcoin.networks.bitcoin;
const psbt = new bitcoin.Psbt({ community });

psbt.addInput({
    hash: "91feea5f5c7b67b3e56c0f5d23d6da3065855c23b4cc7dded8efd8ff8065500f",
    index: 1,
    witnessUtxo: {
        script: Buffer.from("a914eb762ef1946c2d462764d30112ce27c531fdd60387", 'hex'),
        worth: 894242,
    },
    redeemScript: Buffer.from("???", 'hex'),
});

psbt.addOutput({
    deal with: to_address,
    worth: Math.flooring(quantity * 1e8),
});

psbt.signInput(0, keyPair);
psbt.finalizeInput(0);
const tx = psbt.extractTransaction();
return tx.toHex();

LEAVE A REPLY

Please enter your comment!
Please enter your name here