Bitcoin Forum
May 07, 2024, 09:53:03 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: My understanding of calculating a transaction size  (Read 973 times)
Chris! (OP)
Legendary
*
Offline Offline

Activity: 1382
Merit: 1122



View Profile
April 19, 2017, 03:03:49 AM
 #1

Ok so after a little reading I think I've finally got this but I wanted to confirm with the experts.

If I have a compressed public key then my transaction size will be calculated:

Code:
148x(inputs) + 34x(outputs) + 10x(inputs)

But I also understand that there could be a 1 byte difference in the input sizes.

If you're using an uncompressed public key then your transaction size would be calculated:

Code:
180x(inputs) + 34x(outputs) + 10x(inputs)

Will this give me a fairly accurate fee? I'm also not sure how to tell if my public key is compressed but I guess I could just check bitaddress.org address info.

If I'm wrong or missing something let me know.


Assuming I had a compressed public key with 10 inputs and 1 output it would be calculated:

Code:
148x10 +34x1 +10x10 = 1614 bytes

Then let's assume a nice round fee of 100 Satoshis/byte and my fee would be around 161400 Satoshis or 0.001614BTC.

Did I get that right?
1715075583
Hero Member
*
Offline Offline

Posts: 1715075583

View Profile Personal Message (Offline)

Ignore
1715075583
Reply with quote  #2

1715075583
Report to moderator
"Your bitcoin is secured in a way that is physically impossible for others to access, no matter for what reason, no matter how good the excuse, no matter a majority of miners, no matter what." -- Greg Maxwell
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715075583
Hero Member
*
Offline Offline

Posts: 1715075583

View Profile Personal Message (Offline)

Ignore
1715075583
Reply with quote  #2

1715075583
Report to moderator
1715075583
Hero Member
*
Offline Offline

Posts: 1715075583

View Profile Personal Message (Offline)

Ignore
1715075583
Reply with quote  #2

1715075583
Report to moderator
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3388
Merit: 6606


Just writing some code


View Profile WWW
April 19, 2017, 03:13:46 AM
Last edit: April 19, 2017, 02:13:49 PM by achow101
 #2

Ok so after a little reading I think I've finally got this but I wanted to confirm with the experts.

If I have a compressed public key then my transaction size will be calculated:

Code:
148x(inputs) + 34x(outputs) + 10x(inputs)

But I also understand that there could be a 1 byte difference in the input sizes.
It can vary as much as 4 bytes per input IIRC.

Also, you do not need to do 10x(inputs). There is not an extra 10 bytes per input, rather that is a fixed 10 or so bytes (maximum is actually 26 bytes; depends on the number of inputs and number of outputs).

If you're using an uncompressed public key then your transaction size would be calculated:

Code:
180x(inputs) + 34x(outputs) + 10x(inputs)
Same comment about the 10x(inputs) as above.

Will this give me a fairly accurate fee?
It will tell you the size of your transaction fairly accurately, within a couple of bytes, and that won't really matter when it comes to the transaction fee. It's close enough.

I'm also not sure how to tell if my public key is compressed but I guess I could just check bitaddress.org address info.
A compressed public key will be 32 bytes long, uncompressed is 65. Compressed keys begin with 02 or 03 whereas uncompressed begin with 04.

achow101
Moderator
Legendary
*
Offline Offline

Activity: 3388
Merit: 6606


Just writing some code


View Profile WWW
April 19, 2017, 02:13:33 PM
 #3

It can vary as much as 4 bytes per input IIRC.

Everything I've seen has indicated that the signature data can vary + or - one byte.  I'm not aware of any other variation.  Are you sure about the extra 3 bytes of variation?  If so, do you know where/why that variation occurs?
It seems I am mistaken.

Chris! (OP)
Legendary
*
Offline Offline

Activity: 1382
Merit: 1122



View Profile
April 21, 2017, 03:01:33 AM
 #4

It can vary as much as 4 bytes per input IIRC.

Everything I've seen has indicated that the signature data can vary + or - one byte.  I'm not aware of any other variation.  Are you sure about the extra 3 bytes of variation?  If so, do you know where/why that variation occurs?
It seems I am mistaken.

Ok so if we were to write out the formula what would it be (understanding that of course there is a range)? The 10-26 bytes aren't multiplied by the number of inputs though, was that part still right?
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10555



View Profile
April 21, 2017, 04:31:16 AM
 #5

The problem with "making up a formula" is that there are too many factors to consider. for example that 10 byte that we say is fixed, is not really a fixed 10 byte. it is the sum of the following:
4 (fixed) + 1 (variable) + 1 (variable) + 4 (fixed) = 10
although it is rare to have that many outputs to have that 2 bytes instead of 1.

or for example inside the transaction when you say 148 (or 147) * inputs that is if you are not using a multisig.

https://bitcoin.org/en/developer-reference#raw-transaction-format

Version (4 Bytes)
TxIn Count (1B) since you won't have that many outputs to spend

number of inputs *{
Outpoint (36B)
Script Length (1B) the most common cases
ScriptSig(~106-107 B)
Sequence (4B)
}

TxOut Count (1B) since you won't be having more than a couple

number of new outputs *{
Value (8B)
Script Length(1B) the most common cases
Script (25) the most common cases
}

LockTime (4B)

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Chris! (OP)
Legendary
*
Offline Offline

Activity: 1382
Merit: 1122



View Profile
April 23, 2017, 10:09:22 PM
 #6

The problem with "making up a formula" is that there are too many factors to consider. for example that 10 byte that we say is fixed, is not really a fixed 10 byte. it is the sum of the following:
4 (fixed) + 1 (variable) + 1 (variable) + 4 (fixed) = 10
although it is rare to have that many outputs to have that 2 bytes instead of 1.

or for example inside the transaction when you say 148 (or 147) * inputs that is if you are not using a multisig.

https://bitcoin.org/en/developer-reference#raw-transaction-format

Version (4 Bytes)
TxIn Count (1B) since you won't have that many outputs to spend

number of inputs *{
Outpoint (36B)
Script Length (1B) the most common cases
ScriptSig(~106-107 B)
Sequence (4B)
}

TxOut Count (1B) since you won't be having more than a couple

number of new outputs *{
Value (8B)
Script Length(1B) the most common cases
Script (25) the most common cases
}

LockTime (4B)

So then the formulae I'm using are close enough that it shouldn't be off by 10% and should at the very least should be a good indication of what the fee should be, right? In the end that's all I'm looking for is an estimate.
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10555



View Profile
April 24, 2017, 05:11:13 AM
 #7

So then the formulae I'm using are close enough that it shouldn't be off by 10% and should at the very least should be a good indication of what the fee should be, right? In the end that's all I'm looking for is an estimate.

as long as you don't have some crazy number of TX_In and TX_Out (something like 300) the fixed amount of bytes you add is 10 (4 version + 1 TxIn count + 1 TxOut count + 4 LockTime).

also as long as you are using a Pay To PubKey Hash and also use Compressed private keys (like the address you have in your profile which has a compressed private key) your formula is correct.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Chris! (OP)
Legendary
*
Offline Offline

Activity: 1382
Merit: 1122



View Profile
April 24, 2017, 12:25:50 PM
 #8

So then the formulae I'm using are close enough that it shouldn't be off by 10% and should at the very least should be a good indication of what the fee should be, right? In the end that's all I'm looking for is an estimate.

as long as you don't have some crazy number of TX_In and TX_Out (something like 300) the fixed amount of bytes you add is 10 (4 version + 1 TxIn count + 1 TxOut count + 4 LockTime).

also as long as you are using a Pay To PubKey Hash and also use Compressed private keys (like the address you have in your profile which has a compressed private key) your formula is correct.

Great then it's good enough for me! I just have some paper wallets that I was wondering what the fees would be if I tried to sweep them some day. This helps a lot. Thanks everyone.
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!