I am sorry if this has been answered earlier than, however I have not discovered anybody actually carry this up.
I’m making an attempt to assemble a PSBT, which assumes a set feerate and a set quantity to ship to some tackle. Any additional sats is change again to the sender. One thing like:
const psbt = new Psbt({ community: bitcoin.networks.bitcoin });
psbt.addInput({hash, index, witnessUtxo: {...}});
psbt.addOutput({tackle: recipient, worth: amountToSend});
psbt.addOutput({tackle: sender, worth: changeAmount}); // complete inputs - amountToSend - charges
Nevertheless, creating that final change output looks like a round train:
- To find out the final output so as to add to the PSBT, we have to know the precise charge in satoshis we’re keen to spend.
- To know the precise charge in satoshis, we have to know the digital bytes that the tx will devour, which requires us having a completely constructed and signed PSBT i.e.
signedPsbt.extractTransaction().virtualSize();
.
Am I lacking one thing apparent right here? Is there one thing to assist estimate vsize earlier than signing a PSBT (by estimating the scale of signatures)? Or one thing to assist estimate charges given variety of inputs and outputs?
Any assistance is appreciated. Thanks prematurely!