Author

Topic: How to calculate bitcoin segwit transaction fee and some other questions. (Read 246 times)

HCP
legendary
Activity: 2086
Merit: 4361
But I did not see the formula on another site, so this makes it not authentic yet for me, supposing I have seeing it on two or three sites, I would have believed.
Just to confirm for you what the others have indicated... Direct from Bitcoin Core in their Segwit Wallet Developers guide:
Transaction Fee Estimation
  • Instead of transaction size, a new metric is defined, called “virtual size” (vsize)
  • vsize of a transaction equals to 3 times of the size with original serialization, plus the size with new serialization, divide the result by 4 and round up to the next integer. For example, if a transaction is 200 bytes with new serialization, and becomes 99 bytes with marker, flag, and witness removed, the vsize is (99 * 3 + 200) / 4 = 125 with round up.
  • vsize of a non-segwit transaction is simply its size
  • Transaction fee should be estimated by comparing the vsize with other transactions, not the size.
  • Developers should be careful not to make an off-by-4-times mistake in fee estimation.


There is also a lot of other really useful information in that guide relating to Segwit.
legendary
Activity: 1512
Merit: 4795
Leading Crypto Sports Betting & Casino Platform
2. You have answer in the above linked article. You can further check with this website- https://coinb.in/#fees
You can use that site to get transaction size from your input details:
- Transaction types: Regular, Segwit, Multisig. It means for legacy, segwit, or multisig transactions
- Number of inputs, outputs
Or you can use that another site: https://www.buybitcoinworldwide.com/fee-calculator/ and don't forget to check Johoe's site as well
Okay, nicely replied. I really now understood what you people commented, I do not have problem with the transaction size but with normal segwit transactions that included transaction weight. I see your link also very useful.
hero member
Activity: 1722
Merit: 801
2. You have answer in the above linked article. You can further check with this website- https://coinb.in/#fees
You can use that site to get transaction size from your input details:
- Transaction types: Regular, Segwit, Multisig. It means for legacy, segwit, or multisig transactions
- Number of inputs, outputs
Or you can use that another site: https://www.buybitcoinworldwide.com/fee-calculator/ and don't forget to check Johoe's site as well
legendary
Activity: 2268
Merit: 18748
I want to make a topic about segwit address transaction fee
Can I suggest that if this proposed topic is meant to be a guide, a summary of the information, or to otherwise educate others, that you do not make it? If you do not have a firm grasp on the material yourself, trying to educate others on it only leads to incorrect information and more confusion. Much better to start a thread like this one asking questions so the correct information can be given.

But I did not see the formula on another site, so this makes it not authentic yet for me, supposing I have seeing it on two or three sites, I would have believed.
That Stack Exchange answer was written by Pieter Wuille, one of the top Bitcoin Core developers. You can trust that it is accurate.

That formula is also saying the same thing that nc50lc has said above, just in a different way. It is taking the the non-witness data ("base_size"), multiplying it by 3, and adding it to the combined non-witness and witness data ("total_size"). This results in the non-witness data being counted 4 times in total, and the witness data being counted once, which gives you the weight of the transaction. Divide everything by 4 to get the virtual size in vbytes.
legendary
Activity: 2534
Merit: 6080
Self-proclaimed Genius
1. What is the formula to calculate segwit transaction fee in which the weight will be included.
There's no fancy formula, all you have to do is to multiply non-Witness data by 4 and Witness data by 1 and that's the Weight of the transaction.
Then divide the weight by four to get the 'vBytes', that's basically the same as what your client (eg. Electrum) is displaying as 'Bytes' if it supports SegWit.
Lastly, compute based from the usual 'n sat/B' fee rate.
Read https://en.bitcoinwiki.org/wiki/Block_weight#Detailed_example to know which parts of the transaction are 'Witness' data.

Quote from: Charles-Tim
2. If sending to another type of address like the compatible and legacy, will the fee still be reduce? Also, if sending from another type of address like the compatible and legacy to segwit, will the fee be like normal transaction fee?
Outputs wont count with the virtual size reduction since those are non-Witness data.

Quote from: Charles-Tim
3. Why is P2SH (compatible) address fee also low compared to legacy address when both use transaction size to calculate the fee.
You mean P2SH-SegWit? It's not the "raw size", but "virtual size".
Because some parts of it is Witness data and as I said, those are counted as '1' Weight unit compared to '4' for non-Witness data.

See it for yourself by checking your Electrum transaction history and check it on blockstream.info, the weight should be four times the 'bytes' displayed in Electrum whether it's SegWit or not.
If you want to see the raw Bytes, use blockchain.com's explorer.
legendary
Activity: 3472
Merit: 10611
2. If sending to another type of address like the compatible and legacy, will the fee still be reduce? Also, if sending from another type of address like the compatible and legacy to segwit, will the fee be like normal transaction fee?
bitcoin doesn't care to which address you are sending your coins. all it cares about is the weight of the resulting transaction and nodes compute fee/vbyte based on that. the SO link posted above.

3. Why is P2SH (compatible) address fee also low compared to legacy address when both use transaction size to calculate the fee.
3. In shorts, it consumes less data I guess. But I don't know how technically it happens. Wait for the bros to join the discussion.
transactions containing witness consume more "data" because the raw bytes is increased due to addition of a couple of new bytes indicating existence of witness and the item count,...
what is less is the weight and in fact a nested SegWit script (witness wrapped inside a P2SH script) consumes a lot more space than a normal SegWit script but it has less weight because it still moves the signature(s) to the witness field hence decreasing the weight.

something like this (skipping some bytes that are shared such as txincount):
legacy tx:
[version][outpoint][Sig=~72B][Pubkey=33B][tx_out_list][locktime]
SegWit tx:
[version][Flag=2B][outpoint][empty][tx_out_list][witCount=1B][Sig=~72B][Pubkey=33B][locktime]
Nested SegWit tx:
[version][Flag=2B][outpoint][redeemScript=~22B][tx_out_list][witCount=1B][Sig=~72B][Pubkey=33B][locktime]
legendary
Activity: 1512
Merit: 4795
Leading Crypto Sports Betting & Casino Platform
I have read about it on the link you provided before
https://bitcoin.stackexchange.com/questions/87275/how-to-calculate-segwit-transaction-fee-in-bytes

But I did not see the formula on another site, so this makes it not authentic yet for me, supposing I have seeing it on two or three sites, I would have believed.
hero member
Activity: 1358
Merit: 851
1. What is the formula to calculate segwit transaction fee in which the weight will be included.

2. If sending to another type of address like the compatible and legacy, will the fee still be reduce? Also, if sending from another type of address like the compatible and legacy to segwit, will the fee be like normal transaction fee?

3. Why is P2SH (compatible) address fee also low compared to legacy address when both use transaction size to calculate the fee.
1. Check this- https://bitcoin.stackexchange.com/questions/87275/how-to-calculate-segwit-transaction-fee-in-bytes
2. You have answer in the above linked article. You can further check with this website- https://coinb.in/#fees
3. In shorts, it consumes less data I guess. But I don't know how technically it happens. Wait for the bros to join the discussion.
legendary
Activity: 1512
Merit: 4795
Leading Crypto Sports Betting & Casino Platform
I want to make a topic about segwit address transaction fee, I have know how to calculate legacy address but I have not known how to about segwit calculations, I have read the transaction fee is calculated not only using the transactions size but that the main thing that makes it different from normal fee is the transaction weight. These are my questions

1. What is the formula to calculate segwit transaction fee in which the weight will be included.

2. If sending to another type of address like the compatible and legacy, will the fee still be reduce? Also, if sending from another type of address like the compatible and legacy to segwit, will the fee be like normal transaction fee?

3. Why is P2SH (compatible) address fee also low compared to legacy address when both use transaction size to calculate the fee.

Jump to: