Tag Archives: bitcoin

I am creating a miner in C++ for solo mining, and am struggling to create the proper coinbase transaction.

Say I have a bc1 address, like bc1qfc7fameteuguetm0kfzypnvf2ju6wppdvj6tkc , what would be and example of a coinbase transaction with this, and how would I get to it?

https://developer.bitcoin.org/reference/transactions.html

01000000 .............................. Version

01 .................................... Number of inputs
| 00000000000000000000000000000000
| 00000000000000000000000000000000 ...  Previous outpoint TXID
| ffffffff ............................ Previous outpoint index
|
| 29 .................................. Bytes in coinbase // height+message below, byte length
| |
| | 03 ................................ Bytes in height
| | | 4e0105 .......................... Height: 328014
| |
| | 062f503253482f0472d35454085fffed
| | f2400000f90f54696d65202620486561
| | 6c74682021 ........................ Arbitrary data // custom data, include extranonce here
| 00000000 ............................ Sequence // i thought this was all Fs?

01 .................................... Output count
| 2c37449500000000 .................... // coinbase value
| ????????????????? ............. // here, how do i properly fill this part??
| 00000000 ............................ Locktime

These are the parts needed to create the data for the transaction.

Everything up to the output, i understand. but i dont know what to put between the coinbase value and locktime. how does the address convert to hex? what OP codes do i need? and is this transaction layout correct?

And then I would then hash it and input it as a new transaction into the block as like so,

tx = {
  "data" : "<hex string mentioned above>",
  "hash" : "<double sha256 of data above>",
}

is that the only data i need for the json?

Thanks in advance.