Bitcoin Tutorials - Herong's Tutorial Examples - Version 1.03, by Dr. Herong Yang
Data Structure of Coinbase Transaction
This section describes the data structure of a coinbase transaction.
A coinbase transaction is a special transaction created by the miner of the block. It is used for the miner to collect the mining reward and transaction fees from other transactions in the same block.
Each Bitcoin block should have only one coinbase transaction. And it is placed as the first transaction in the transaction list.
Since it collects Bitcoin funds from coinbase and other transactions, A coinbase transaction has no inputs to represent outputs of older transactions. So a fake input is used in the coinbase transaction with the following data structure:
Bytes Name Description 36 previous_output Fake output, consisting of a 32-byte of null as the TXID and a 4-byte of 0xffffffff as output index number (vout). Varies script bytes The number of bytes in height and coinbase script. Varies height The height of this block in the blockchain with the first byte as the height byte count. Varies coinbase script Arbitrary data not exceeding 100 bytes (including height bytes). Miners commonly place an extra nonce in this field to update the block header merkle root during hashing. 4 sequence Sequence number.
Now let's decode a raw coinbase transaction 02f754075a7fae665fa4440b799c711e319a56357eda6e6bc84d40220b200361 on the Bitcoin test network:
C:\>\local\bitcoin-0.15.1\bin\bitcoin-cli.exe -testnet getrawtransaction 02f754075a7fae665fa4440b799c711e319a56357eda6e6bc84d40220b200361 false 01000000010000000000000000000000000000000000000000000000000000000000000000 ffffffff1d030f8d13049faa805a063538706f6f6c0c00010000fe22030000000000ffffff ff015341cb04000000001976a914f11298ce777cb5db5c09250cad4eb856b1e366ef88ac00 000000
Here the decoded fields and values:
Hex value Name and Description 01000000 version - Transaction version 1 01 tx_in_count - 1 transaction input 0000000000000000000000000000000000000000000000000000000000000000 outpoint txid - fake transaction ID for coinbase transaction ffffffff outpoint index - fake index 1d script bytes - The height and coinbase script has 29 bytes. 030f8d13 height - 0x03-byte little-endian integer: 0x0f8d13 = 1281295 049faa805a063538706f6f6c0c00010000fe22030000000000 coinbase script - Arbitrary data entered by the miner ffffffff sequence - End of this input 01 tx_out_count - 1 transaction output 5341cb0400000000 value - Amount of the first output in little-endian integer format: 80429395 Satoshis = 0.80429395 BTC 19 script bytes - The pubkey script has 25 bytes 76a914f11298ce777cb5db5c09250cad4eb856b1e366ef88ac pubkey script - Represents the account address of the miner 00000000 lock_time - It should be a reference to timestamp or block height
Last update: 2018.
Table of Contents