Bitcoin Forum
November 02, 2024, 05:18:59 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to calculate bitcoin segwit transaction fee and some other questions.  (Read 240 times)
Charles-Tim (OP)
Legendary
*
Offline Offline

Activity: 1722
Merit: 5196


Leading Crypto Sports Betting & Casino Platform


View Profile
July 26, 2020, 08:19:31 PM
 #1

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.


..Stake.com..   ▄████████████████████████████████████▄
   ██ ▄▄▄▄▄▄▄▄▄▄            ▄▄▄▄▄▄▄▄▄▄ ██  ▄████▄
   ██ ▀▀▀▀▀▀▀▀▀▀ ██████████ ▀▀▀▀▀▀▀▀▀▀ ██  ██████
   ██ ██████████ ██      ██ ██████████ ██   ▀██▀
   ██ ██      ██ ██████  ██ ██      ██ ██    ██
   ██ ██████  ██ █████  ███ ██████  ██ ████▄ ██
   ██ █████  ███ ████  ████ █████  ███ ████████
   ██ ████  ████ ██████████ ████  ████ ████▀
   ██ ██████████ ▄▄▄▄▄▄▄▄▄▄ ██████████ ██
   ██            ▀▀▀▀▀▀▀▀▀▀            ██ 
   ▀█████████▀ ▄████████████▄ ▀█████████▀
  ▄▄▄▄▄▄▄▄▄▄▄▄███  ██  ██  ███▄▄▄▄▄▄▄▄▄▄▄▄
 ██████████████████████████████████████████
▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄
█  ▄▀▄             █▀▀█▀▄▄
█  █▀█             █  ▐  ▐▌
█       ▄██▄       █  ▌  █
█     ▄██████▄     █  ▌ ▐▌
█    ██████████    █ ▐  █
█   ▐██████████▌   █ ▐ ▐▌
█    ▀▀██████▀▀    █ ▌ █
█     ▄▄▄██▄▄▄     █ ▌▐▌
█                  █▐ █
█                  █▐▐▌
█                  █▐█
▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀█
▄▄█████████▄▄
▄██▀▀▀▀█████▀▀▀▀██▄
▄█▀       ▐█▌       ▀█▄
██         ▐█▌         ██
████▄     ▄█████▄     ▄████
████████▄███████████▄████████
███▀    █████████████    ▀███
██       ███████████       ██
▀█▄       █████████       ▄█▀
▀█▄    ▄██▀▀▀▀▀▀▀██▄  ▄▄▄█▀
▀███████         ███████▀
▀█████▄       ▄█████▀
▀▀▀███▄▄▄███▀▀▀
..PLAY NOW..
RapTarX
Hero Member
*****
Offline Offline

Activity: 1358
Merit: 851



View Profile
July 26, 2020, 09:02:29 PM
 #2

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.

Charles-Tim (OP)
Legendary
*
Offline Offline

Activity: 1722
Merit: 5196


Leading Crypto Sports Betting & Casino Platform


View Profile
July 26, 2020, 09:20:58 PM
 #3

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.

..Stake.com..   ▄████████████████████████████████████▄
   ██ ▄▄▄▄▄▄▄▄▄▄            ▄▄▄▄▄▄▄▄▄▄ ██  ▄████▄
   ██ ▀▀▀▀▀▀▀▀▀▀ ██████████ ▀▀▀▀▀▀▀▀▀▀ ██  ██████
   ██ ██████████ ██      ██ ██████████ ██   ▀██▀
   ██ ██      ██ ██████  ██ ██      ██ ██    ██
   ██ ██████  ██ █████  ███ ██████  ██ ████▄ ██
   ██ █████  ███ ████  ████ █████  ███ ████████
   ██ ████  ████ ██████████ ████  ████ ████▀
   ██ ██████████ ▄▄▄▄▄▄▄▄▄▄ ██████████ ██
   ██            ▀▀▀▀▀▀▀▀▀▀            ██ 
   ▀█████████▀ ▄████████████▄ ▀█████████▀
  ▄▄▄▄▄▄▄▄▄▄▄▄███  ██  ██  ███▄▄▄▄▄▄▄▄▄▄▄▄
 ██████████████████████████████████████████
▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄
█  ▄▀▄             █▀▀█▀▄▄
█  █▀█             █  ▐  ▐▌
█       ▄██▄       █  ▌  █
█     ▄██████▄     █  ▌ ▐▌
█    ██████████    █ ▐  █
█   ▐██████████▌   █ ▐ ▐▌
█    ▀▀██████▀▀    █ ▌ █
█     ▄▄▄██▄▄▄     █ ▌▐▌
█                  █▐ █
█                  █▐▐▌
█                  █▐█
▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀█
▄▄█████████▄▄
▄██▀▀▀▀█████▀▀▀▀██▄
▄█▀       ▐█▌       ▀█▄
██         ▐█▌         ██
████▄     ▄█████▄     ▄████
████████▄███████████▄████████
███▀    █████████████    ▀███
██       ███████████       ██
▀█▄       █████████       ▄█▀
▀█▄    ▄██▀▀▀▀▀▀▀██▄  ▄▄▄█▀
▀███████         ███████▀
▀█████▄       ▄█████▀
▀▀▀███▄▄▄███▀▀▀
..PLAY NOW..
pooya87
Legendary
*
Offline Offline

Activity: 3626
Merit: 10996


Crypto Swap Exchange


View Profile
July 27, 2020, 03:00:45 AM
Merited by o_e_l_e_o (2)
 #4

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]

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
nc50lc
Legendary
*
Offline Offline

Activity: 2590
Merit: 6325


Self-proclaimed Genius


View Profile
July 27, 2020, 10:26:35 AM
Merited by o_e_l_e_o (2)
 #5

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.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
o_e_l_e_o
In memoriam
Legendary
*
Offline Offline

Activity: 2268
Merit: 18726


View Profile
July 27, 2020, 10:54:14 AM
Merited by TheArchaeologist (1)
 #6

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.
OcTradism
Hero Member
*****
Offline Offline

Activity: 1918
Merit: 860



View Profile WWW
July 28, 2020, 01:13:05 PM
 #7

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

███████████████████████████
███████▄████████████▄██████
████████▄████████▄████████
███▀█████▀▄███▄▀█████▀███
█████▀█▀▄██▀▀▀██▄▀█▀█████
███████▄███████████▄███████
███████████████████████████
███████▀███████████▀███████
████▄██▄▀██▄▄▄██▀▄██▄████
████▄████▄▀███▀▄████▄████
██▄███▀▀█▀██████▀█▀███▄███
██▀█▀████████████████▀█▀███
███████████████████████████
.
.Duelbits.
..........UNLEASH..........
THE ULTIMATE
GAMING EXPERIENCE
DUELBITS
FANTASY
SPORTS
████▄▄█████▄▄
░▄████
███████████▄
▐███
███████████████▄
███
████████████████
███
████████████████▌
███
██████████████████
████████████████▀▀▀
███████████████▌
███████████████▌
████████████████
████████████████
████████████████
████▀▀███████▀▀
.
▬▬
VS
▬▬
████▄▄▄█████▄▄▄
░▄████████████████▄
▐██████████████████▄
████████████████████
████████████████████▌
█████████████████████
███████████████████
███████████████▌
███████████████▌
████████████████
████████████████
████████████████
████▀▀███████▀▀
/// PLAY FOR  FREE  ///
WIN FOR REAL
..PLAY NOW..
Charles-Tim (OP)
Legendary
*
Offline Offline

Activity: 1722
Merit: 5196


Leading Crypto Sports Betting & Casino Platform


View Profile
July 28, 2020, 02:41:52 PM
 #8

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.

..Stake.com..   ▄████████████████████████████████████▄
   ██ ▄▄▄▄▄▄▄▄▄▄            ▄▄▄▄▄▄▄▄▄▄ ██  ▄████▄
   ██ ▀▀▀▀▀▀▀▀▀▀ ██████████ ▀▀▀▀▀▀▀▀▀▀ ██  ██████
   ██ ██████████ ██      ██ ██████████ ██   ▀██▀
   ██ ██      ██ ██████  ██ ██      ██ ██    ██
   ██ ██████  ██ █████  ███ ██████  ██ ████▄ ██
   ██ █████  ███ ████  ████ █████  ███ ████████
   ██ ████  ████ ██████████ ████  ████ ████▀
   ██ ██████████ ▄▄▄▄▄▄▄▄▄▄ ██████████ ██
   ██            ▀▀▀▀▀▀▀▀▀▀            ██ 
   ▀█████████▀ ▄████████████▄ ▀█████████▀
  ▄▄▄▄▄▄▄▄▄▄▄▄███  ██  ██  ███▄▄▄▄▄▄▄▄▄▄▄▄
 ██████████████████████████████████████████
▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄
█  ▄▀▄             █▀▀█▀▄▄
█  █▀█             █  ▐  ▐▌
█       ▄██▄       █  ▌  █
█     ▄██████▄     █  ▌ ▐▌
█    ██████████    █ ▐  █
█   ▐██████████▌   █ ▐ ▐▌
█    ▀▀██████▀▀    █ ▌ █
█     ▄▄▄██▄▄▄     █ ▌▐▌
█                  █▐ █
█                  █▐▐▌
█                  █▐█
▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀█
▄▄█████████▄▄
▄██▀▀▀▀█████▀▀▀▀██▄
▄█▀       ▐█▌       ▀█▄
██         ▐█▌         ██
████▄     ▄█████▄     ▄████
████████▄███████████▄████████
███▀    █████████████    ▀███
██       ███████████       ██
▀█▄       █████████       ▄█▀
▀█▄    ▄██▀▀▀▀▀▀▀██▄  ▄▄▄█▀
▀███████         ███████▀
▀█████▄       ▄█████▀
▀▀▀███▄▄▄███▀▀▀
..PLAY NOW..
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4361

<insert witty quote here>


View Profile
July 28, 2020, 10:45:25 PM
 #9

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.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!