bitcoinjs – find out how to get vsize earlier than psbt finalized – CoinNewsTrend

bitcoinjs – find out how to get vsize earlier than psbt finalized


I’m utilizing bitcoinjs-lib to assemble a transaction by means of PSBT, however I’m having problem acquiring the digital measurement (vsize). My course of is as follows:

  1. Receive the person’s handle by means of the browser pockets (OKX Pockets).

  2. Retrieve the UTXO listing for that handle by way of a REST API.

  3. Assemble the PSBT, including inputs and outputs (assuming payment=0 when calculating change).

  4. Ship psbt.toHex() to the browser pockets to request the person’s signature (unsigned PSBT can’t be finalized).

  5. Calculate the payment utilizing Psbt.fromHex(signResult).extractTransaction().virtualSize() * feeRate.

  6. Recalculate the change primarily based on the payment, resend the modified PSBT to the pockets to request the person’s signature, then reconstruct the PSBT from the signature consequence to get the transaction and broadcast it.

Throughout this course of, I must request the person’s signature twice, which leads to a poor person expertise.

Is there any option to signal solely as soon as whereas nonetheless calculating the change primarily based on the precise vsize?



Supply hyperlink