Bitcoin Forum
May 06, 2024, 01:43:13 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Estimating transaction size in bytes per element of the transaction  (Read 94 times)
IfPtr (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 1


View Profile
June 06, 2018, 10:18:39 PM
 #1

Hello guys,

I have been reading about transactions recently and I am interested in understanding how the size of a transaction is influenced by its building elements.
So for example we know that a transaction contains:
  • a certain number of inputs
  • a cetrain number of outputs
  • a locking scrpit (scriptPubKey)
  • an unlocking script (scriptSig)

... and other elements. What I would like to know is how much each of the elements contributes to the total size of the transaction. So for example how many bytes are the typical scripts? Do they vary in size? Do inputs have a (approximately) fixed size in bytes? Do outputs have a (approximately) fixed size in bytes? Is everything thus a simple game of addition?

Thank you very much for taking the time to read my question!
1714959793
Hero Member
*
Offline Offline

Posts: 1714959793

View Profile Personal Message (Offline)

Ignore
1714959793
Reply with quote  #2

1714959793
Report to moderator
Activity + Trust + Earned Merit == The Most Recognized Users on Bitcointalk
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714959793
Hero Member
*
Offline Offline

Posts: 1714959793

View Profile Personal Message (Offline)

Ignore
1714959793
Reply with quote  #2

1714959793
Report to moderator
1714959793
Hero Member
*
Offline Offline

Posts: 1714959793

View Profile Personal Message (Offline)

Ignore
1714959793
Reply with quote  #2

1714959793
Report to moderator
btj
Member
**
Offline Offline

Activity: 115
Merit: 16


View Profile
June 07, 2018, 04:47:05 AM
Last edit: June 08, 2018, 03:52:23 AM by btj
 #2

Quote
Size of transaction = Number inputs * (Input Size) + Number of outputs * (Output Size) + 10 Bytes extra fixed fee required for the framework of the transaction

How to get the P2PKH input size ?

Quote
PREVOUT  + SCRIPTSIG + sequence = 32 + 4 + 1 + 1 + (71 or 72) + 1 + 33 (Compressed) + 4 = 147 or 148

Quote
PREVOUT: hash (32 bytes)
         index (4 bytes)
SCRIPTSIG: length (1 byte)
           CONTENTS: push opcode (1 byte)
                     signature (71 or 72 bytes)
                     push opcode (1 byte)
                     pubkey (33 bytes for compressed, 65 for uncompressed)
sequence (4 bytes)
Source: https://bitcoin.stackexchange.com/questions/48279/how-big-is-the-input-of-a-p2pkh-transaction

Quote
   Legacy input size: 148 bytes (compressed)

    Legacy output size: 34 bytes (compressed)

    Segwit input size: 104 bytes
    Segwit output size: 32 bytes

Outputs for P2PKH and P2SH are both the same size: 34 bytes

So let's take an example and calculate the size:
https://blockchain.info/tx/7e46a5ea9d9c19cd4d0c3d0a287419d7c1ae13049ac7ab8860b6ee0cec4ead17

We have 1 input
There 2 Output

Quote
So the transaction size ~= 13 * 148 + 2 * 34 + 10 ~= 226 Bytes

Check this link, you will learn more about it:
https://blog.rmcsoft.com/how-to-calculate-bitcoin-transaction-fee/
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4616



View Profile
June 08, 2018, 04:04:19 PM
 #3

So for example we know that a transaction contains:
  • a certain number of inputs
  • a cetrain number of outputs

Correct.

  • a locking scrpit (scriptPubKey)

No.

Not A locking script.

Each output has its own locking script to lock THAT output, so if you have multiple outputs then you have multiple locking scripts.

More importantly, EACH output IS two things: a locking script, and the amount of satoshis being locked.

That's it.  That's the entire output.

  • an unlocking script (scriptSig)

No.

Not AN unlocking script.

Each input has its own unlocking script to unlock THAT input, so if you have multiple inputs then you have multiple unlocking scripts.

More importantly, EACH input IS three things: a reference to a previously unspent output, and the unlocking script that allows you to spend that previous output, a sequence number.

That's it.  That's the entire input.

... and other elements.

There are about 10 bytes of "other elements".

  • A 4 byte version number
  • 1 or more bytes indicating the quantity of inputs
  • 1 or more bytes indicating the quantity of outputs
  • A 4 byte locktime

Unless you have significantly more than a hundred inputs or significantly more than a hundred outputs, the number of inputs and outputs will not need more than 1 byte each.
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!