## What is the format of the coinbase transaction?

18

9

I'm trying to understand the format of the coinbase transaction. I've read that it is arbitrary and not specified. I'm wondering because I need to generate mining work and create an internal pool. As I've found out, you can change the ntime, nonce and extranonce fields. The last one should be suited in the coinbase parameter, right? So, can anyone help me analyze the content of the coinbase transaction and how am I supposed to build one, so all miners in my pool could have different headers for hashing? A step-by-step guide on an existing block would be much appreciated, links and other stuff too.

17

A coinbase transaction follows the same format as a normal transaction, except:

• It has exactly one txin
• This txin's prevout hash is 0000...0000.
• This txin's prevout index is 0xFFFFFFFF
• The txin's prevout script is an arbitrary byte array (it doesn't have to be a valid script, though this is commonly done anyway) of 2 to 100 bytes. It has to start with a correct push of the block height (see BIP34).
• The sum of the txout's values cannot exceed the subsidy (25 BTC for now, halves every 210000 blocks) plus the fees of the non-coinbase transactions in the same block.

About the scriptSig being an arbitrary byte array, there is one caveat: the checksig operations in it are counted towards the block sigop limit (20000), so you probably don't want to accidentally trigger this. Making it a list of just push operations (including of the extranonce) avoids that.

7

Look at block #280963. Look at coinbase transaction d1c6b8...fd08. You can see CoinBase data:

038349040d00456c69676975730052d8f72ffabe6d6dd991088decd13e658bbecc0b2b4c87306f637828917838c02a5d95d0e1bdff9b0400000000000000002f73733331312f00906b570400000000e4050000


This is a script. Look at wiki for details. In coinbase transaction this script can contain any data. If you change this data, merkle root will change as well, and diffirent miners can start changing nonce/timestamp for merlke root, that you provides for them. Look at wiki for more information about merkle tree.

Coinbase transaction contains single input. This is input is not used, and it contains 32 bytes zeros as previous tx. Look at wiki for more information about what data transaction contains. I provide as example of decoding raw coinbase transaction.

> getrawtransaction d1c6b8140246950475735394b0ac68f9ada60d313d2b5308afbc569c84f7fd08

01000000 - version
01 - input count
0000000000000000000000000000000000000000000000000000000000000000 - prev tx
ffffffff - prev out n
53 - length of coinbase script
038349040d00456c69676975730052d8f72ffabe6d6dd991088decd13e658bbecc0b2b4c87306f637828917838c02a5d95d0e1bdff9b0400000000000000002f73733331312f00906b570400000000e4050000 - coinbase script
ffffffff - sequence
01 - output count
bf20879500000000 - 2508660927, satoshi count, or 25.08660927 BTC
19 - script length