Format of Various Fields in Serialized Transaction
Version
Example: 01000000
Size: 4 bytes
Format: Little-Endian
Description: The version number for the transaction. Used to enable new features.
Input Count
Example: 02
Size: variable
Format: Compact Size
Description: Indicates the number of inputs.
Input(s)
TXID:
Example: b9a2c28ea00905a5d24a172598b9574fbd973fc085df49901208a358d29a233b
Size: 32 bytes
Format: Natural Byte Order
Description: The TXID of the transaction containing the output you want to spend.
VOUT:
Example: 00000000
Size: 4 bytes
Format: Little-Endian
Description: The index number of the output you want to spend.
ScriptSig Size:
Example: 17
Size: variable
Format: Compact Size
Description: The size in bytes of the upcoming ScriptSig.
ScriptSig:
Example: 16001415ff0337937ecadd10ce56ffdfd4674817613223
Size: variable
Format: Script
Description: The unlocking code for the output you want to spend.
Sequence:
Example: f0ffffff
Size: 4 bytes
Format: Little-Endian
Description: Set whether the transaction can be replaced or when it can be mined.
Output Count
Example: 02
Size: variable
Format: Compact Size
Description: Indicates the number of outputs.
Output(s)
Amount:
Example: 007daf0100000000
Size: 8 bytes
Format: Little-Endian
Description: The value of the output in satoshis.
ScriptPubKey Size:
Example: 19
Size: variable
Format: Compact Size
Description: The size in bytes of the upcoming ScriptPubKey.
ScriptPubKey:
Example: 76a91471a3d2f54b0917dc9d2c877b2861ac52967dec7f88ac
Size: variable
Format: Script
Description: The locking code for this output.
Witness
Stack Items:
Example: 02
Size: variable
Format: Compact Size
Description: The number of items to be pushed on to the stack as part of the unlocking code.
Field
Size:
Example: 47
Size: variable
Format: Compact Size
Description: The size of the upcoming stack item.
Item:
Example: 304…b01
Size: variable
Format: Bytes
Description: The data to be pushed on to the stack.
Locktime
Example: 00000000
Size: 4 bytes
Format: Little-Endian
Description: Set a time or height after which the transaction can be mined.
Note:
When any transaction is serialized these fields are added in the given sequence only.
How to Decode Input Data from a Transaction?
When transactions are transmitted over the network or exchanged between applications, they are serialized. Serialization is most commonly used for encoding data structures for transmission over a network or for storage in a file. The serialization format of a transaction output is shown in Transaction output serialization. This article focuses on discussing steps to decode input data from a transaction.
Table of Content
- What is Serialization?
- Raw Bitcoin Transaction
- Format of Various Fields in Serialized Transaction
- Decoding the Transaction
- Detailed Explanation
- Verification
- Conclusion