I'm trying to calculate SegWit transaction fees in bytes, I have two Segwit inputs and 2 segwit outputs. can anyone calculate this transaction fees if I'm paying 100 Sat per byte?
That depends on what those inputs and outputs look like.
The formula, as specified in BIP141, is:
- Call base_size the number of bytes needed to serialize the transaction in legacy format (which does not include the witnesses).
- Call total_size the number of bytes needed to serialize the transaction including witnesses.
- The weight of the transaction equals 3*base_size + total_size
- The virtual size of the transaction (which is what feerates are usually expressed against) equals weight/4 or 0.75base_size + 0.25total_size.
Some reference numbers:
- A P2PKH (1... address) output is 34 vbytes.
- A P2SH (3... address) output is 32 vbytes.
- A P2WPKH (bc1q... address of length 42) output is 31 vbytes.
- A P2WSH (bc1q... address of length 62) output is 43 vbytes.
- A P2PKH spend with a compressed public key is 148 vbytes.
- A P2WPKH spend is 68 vbytes.
- A P2SH-P2WPKH spend is 91 vbytes.