VOUT Serialization Hex
VOUT Serialization
Understanding how the VOUT index is written into the raw transaction data is essential for any developer building Bitcoin software. Like most numbers in the protocol, it follows the Little-Endian byte order.
1. Little-Endian Storage
In Little-Endian, the "least significant byte" comes first. This can make raw hex data look confusing to human eyes.
Example: VOUT 0
-
Integer:
0 -
Hex (Big-Endian):
00 00 00 00 -
Raw Serialization:
00 00 00 00
Example: VOUT 1
-
Integer:
1 -
Hex (Big-Endian):
00 00 00 01 -
Raw Serialization:
01 00 00 00
Example: VOUT 256
-
Integer:
256(0x0100 in hex) -
Raw Serialization:
00 01 00 00
2. Placement in the Input
In a raw transaction hex, the VOUT always follows the 32-byte TXID.
[32 Bytes TXID][4 Bytes VOUT][VarInt ScriptLen]...
3. Why Little-Endian?
Bitcoin uses Little-Endian for most numeric values because it was originally developed for x86 processors, which use Little-Endian natively. This allows the computer to read the number directly into memory without performing a conversion.
4. Decoding Cheat Sheet
| VOUT Index | Hex (Protocol) |
|---|---|
| 0 | 00 00 00 00 |
| 1 | 01 00 00 00 |
| 10 | 0a 00 00 00 |
| Coinbase | ff ff ff ff |
In the next section, we will see how the Chainstate Database uses VOUT to track your coins.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: