Coinbase Transaction
A transaction used to claim a block reward.
A coinbase transaction is the first transaction in a block. Miners use it to collect the block reward, and any additional transaction fees.
It’s like putting your details on a self-addressed envelope so you can collect prize winnings.
Usage
When a miner creates a candidate block, the very first space for a transaction is reserved for the coinbase transaction.
Structure
A coinbase transaction is only slightly different to normal transaction data. The main difference is its single “blank” input, which we call the coinbase:
Raw Data (source)
01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4503ec59062f48616f4254432f53756e204368756e2059753a205a6875616e67205975616e2c2077696c6c20796f75206d61727279206d653f2f06fcc9cacc19c5f278560300ffffffff01529c6d98000000001976a914bfd3ebb5485b49a6cf1657824623ead693b5a45888ac00000000
- The
TXIDis all zeros. (We’re not referencing an existing transaction) - The
VOUTis allf’s (the maximum hexadecimal value for this field). (Again, because we’re not trying to refer to an existing output). - The
scriptSigcan actually contain any data you like.1,2 (Because we do not have to unlock anything).
Other than that, you just need to be sure that the sum of your output values does not exceed the block reward + transaction fees you’re collecting.
Notes
BIP 34
As of BIP 34 the scriptSig must start with a push of the height of the block. This change was made to prevent coinbase transactions from having the same TXID.
Example.
In the transaction data above, the 03 gives us the number of bytes being pushed, so the next 3 bytes ec5906 indicates the height of the block.
ec5906 is 416236 when you swap the endianness and convert to decimal.
Messages in coinbase transactions.
Miners often use the scriptSig for strings of text. You just have to decode them (from Hex to ASCII) to read them.
Here are some interesting ones:
| Coinbase Transaction | scriptSig (decoded) | Notes |
|---|---|---|
8b50f51b49f27e7bb0efb0b3bf38d12ce4f7e6258b90a75802a394cb585c879d
|
BitFury/BIP100/ | Miners typically include the name of their mining pool. |
d0ec21e1d73d06be76c2b5b1e5ec486085bda8264229046c11b95f66f2eded83
|
/HaoBTC/Sun Chun Yu: Zhuang Yuan, will you marry me?/ | You can put any string of text in to it. |
4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
|
The Times 03/Jan/2009 Chancellor on brink of second bailout for banks | This is the first coinbase transaction, mined by Satoshi Nakamoto. |
A coinbase transaction must be 100 blocks deep before you can spend its outputs.
This is a safeguard to prevent outputs that originate from the coinbase transaction from becoming unspendable (in the event the mined block moves out of the active chain due to a fork).