<p>Standard script types generally have known maximum sizes, so you can use that to estimate the size of the transaction to determine the fee. Murch has <a href="https://twitter.com/murchandamus/status/1262062602298916865" rel="nofollow noreferrer">created a table</a> with the sizes of these standard script types to make it easier to find this information.</p>
<p>However, as you point out, the easiest way to determine the size is to just sign once, calculate the size and the necessary fee, then discard that signed transaction, modify the original, and sign again.</p>

CC BY-SA 4.0
2023-10-10T19:30:41.110Z
Would using an "effective value" approach not help too?
Pieter Wuille
CC BY-SA 4.0
2023-10-10T19:42:05.530Z
Using effective values still requires estimating the size of the input.
Ava Chow
CC BY-SA 4.0
2023-10-11T15:32:59.173Z
For single-sig types, there is also an overview here: https://bitcoin.stackexchange.com/a/84006/5406
Murch
CC BY-SA 4.0
2023-10-10T19:23:12.340Z
2023-10-10T19:23:12.340Z
Ava Chow
<p>I'm sorry if this has been answered before, but I haven't found anyone really bring this up.</p>
<p>I am trying to construct a PSBT, which assumes a fixed feerate and a fixed amount to send to some address. Any extra sats is change back to the sender. Something like:</p>
<pre class="lang-javascript prettyprint-override"><code>const psbt = new Psbt({ network: bitcoin.networks.bitcoin });
psbt.addInput({hash, index, witnessUtxo: {...}});
psbt.addOutput({address: recipient, value: amountToSend});
psbt.addOutput({address: sender, value: changeAmount}); // total inputs - amountToSend - fees
</code></pre>
<p>However, creating that last change output seems like a circular exercise:</p>
<ul>
<li>To determine the last output to add to the PSBT, we need to know the exact fee in satoshis we're willing to spend.</li>
<li>To know the exact fee in satoshis, we need to know the virtual bytes that the tx will consume, which requires us having a fully constructed and signed PSBT i.e. <code>signedPsbt.extractTransaction().virtualSize();</code>.</li>
</ul>
<p>Am I missing something obvious here? Is there something to help estimate vsize before signing a PSBT (by estimating the size of signatures)? Or something to help estimate fees given number of inputs and outputs?</p>
<p>Any help is appreciated. Thank you in advance!</p>

<transactions><transaction-fees><output><bitcoinjs><bip174-psbt>
Estimating virtual bytes of a transaction seems circular
Sherwin Li
# Estimating virtual bytes of a transaction seems circular

(Asked by: username_0 on 2023-10-10)

I'm sorry if this has been answered before, but I haven't found anyone really bring this up.

I am trying to construct a PSBT, which assumes a fixed feerate and a fixed amount to send to some address. Any extra sats is change back to the sender. Something like:

```javascript
const psbt = new Psbt({ network: bitcoin.networks.bitcoin });
psbt.addInput({hash, index, witnessUtxo: {...}});
psbt.addOutput({address: recipient, value: amountToSend});
psbt.addOutput({address: sender, value: changeAmount}); // total inputs - amountToSend - fees

```

However, creating that last change output seems like a circular exercise:

* To determine the last output to add to the PSBT, we need to know the exact fee in satoshis we're willing to spend.
* To know the exact fee in satoshis, we need to know the virtual bytes that the tx will consume, which requires us having a fully constructed and signed PSBT i.e. `signedPsbt.extractTransaction().virtualSize();`.

Am I missing something obvious here? Is there something to help estimate vsize before signing a PSBT (by estimating the size of signatures)? Or something to help estimate fees given number of inputs and outputs?

Any help is appreciated. Thank you in advance!

**Tags:** transactions, transaction-fees, output, bitcoinjs, bip174-psbt


---

## 1 answers

### Answer by username_1 on 2023-10-10. Score: 2 | Accepted answer

Standard script types generally have known maximum sizes, so you can use that to estimate the size of the transaction to determine the fee. username_3 has [created a table](https://twitter.com/murchandamus/status/1262062602298916865) with the sizes of these standard script types to make it easier to find this information.

However, as you point out, the easiest way to determine the size is to just sign once, calculate the size and the necessary fee, then discard that signed transaction, modify the original, and sign again.

> **Comments:**
> **username_2**: Would using an "effective value" approach not help too?  
> **username_1**: Using effective values still requires estimating the size of the input.  
> **username_3**: For single-sig types, there is also an overview here: https://bitcoin.stackexchange.com/a/84006/5406  

---

