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

Here the decoded fields and values:

Hex value  Name and Description

01000000   version - Transaction version 1

01         tx_in_count - 1 transaction input

           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

           coinbase script - Arbitrary data entered by the miner

ffffffff   sequence - End of this input

01         tx_out_count - 1 transaction output

           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

           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

 About This Book

 Introduction of Bitcoin

 Bitcoin Blockchain

 Bitcoin Wallet

 Bitcoin Core

 Bitcoin Transaction

 Bitcoin-Qt - Bitcoin Core GUI

 Bitcoin Mining

 Bitcoin Consensus Rules

 Bitcoin Block Data Structure

Bitcoin Transaction Data Structure

 Data Properties of Bitcoin Transaction

 Data Structure of Bitcoin Raw Transaction Format

 Decode Bitcoin Raw Transaction Format

Data Structure of Coinbase Transaction

 Calculate Transaction ID API

 Copay - Bitcoin Wallet


 PDF Printing Version