G-N354X1RGVT
BitcoinToday

utxo – Ship transaction with 2 inputs and a couple of outputs utilizing Blockcypher

I am utilizing a node.js client of Blockcypher with the intention to broadcast a Bitcoin transaction.

My code:

const originWalletBalance = getBalance(originAddress)
const charge = calculateFee()
const txBody = {
        charges: charge,
        inputs: [{ addresses: [originAddress] }],
        outputs: [
          { addresses: [targetAddress], worth: amountToSend }
        ]
      }

    //@see https://www.blockcypher.com/dev/bitcoin/#creating-transactions 

    const txSkeleton = await this.bcapi.newTX(physique)
    // construct signer from WIF
    let keys: ECPair = ECPair.fromWIF(signingKey)
    //signing the transaction
    let tmptx = txSkeleton
    tmptx.pubkeys = []
    const SIGHASH_ALL = 0x01
    tmptx["signatures"] = tmptx["tosign"].map((tosign) => {
      tmptx["pubkeys"].push(keys.publicKey.toString("hex"))
      return bitcoin.script.signature.encode(
        keys.signal(Buffer.from(tosign, "hex")),
        SIGHASH_ALL
      ).toString("hex")
    })
    //broadcast tx
    return await this.bcapi.sendTX(tmptx)

The place the steadiness of the origin pockets is 190689, the quantity to ship is 74500, the charge is 25500.

txSkeleton is crated with 2 inputs and a couple of outputs (one for the goal handle and the change to the origin handle, as anticipated):

All of it appear proper, but I am getting the next errors:

"error": "Error constructing enter: Error producing scriptsig when constructing transaction: Invalid signature: Non-canonical signature: mistaken size marker."
"error": "Error constructing enter: Error producing scriptsig when constructing transaction: Invalid signature: Non-canonical signature: mistaken size marker."
"error": "Not sufficient funds in 2 inputs to pay for two outputs, lacking -74500."
"error": "Not sufficient funds in 2 inputs to pay for two outputs, lacking -122500."
"error": "Not sufficient funds after charges in 0 inputs to pay for two outputs, lacking -148000."

Any thought what am I doing mistaken right here?

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button