I am using bitcoinjs-lib to construct a transaction through PSBT, but I am having difficulty obtaining the virtual size (vsize). My process is as follows:

  1. Obtain the user's address through the browser wallet (OKX Wallet).

  2. Retrieve the UTXO list for that address via a REST API.

  3. Construct the PSBT, adding inputs and outputs (assuming fee=0 when calculating change).

  4. Send psbt.toHex() to the browser wallet to request the user's signature (unsigned PSBT cannot be finalized).

  5. Calculate the fee using Psbt.fromHex(signResult).extractTransaction().virtualSize() * feeRate.

  6. Recalculate the change based on the fee, resend the modified PSBT to the wallet to request the user's signature, then reconstruct the PSBT from the signature result to get the transaction and broadcast it.

During this process, I need to request the user's signature twice, which results in a poor user experience.

Is there any way to sign only once while still calculating the change based on the actual vsize?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.