3

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.

1

To create a coinbase transaction you need to send this RPC command to your Bitcoin-Qt

createrawtransaction '[{"txid":"0000000000000000000000000000000000000000000000000000000000000000","vout":2147483647}]{"Your Bitcoin Adress":Amount}'

Why 2147483647 ?

Because the vout must be numeric, and you can't put 0xffffffff

So this will give you 0x7fffffff and the easiest way to do that is to change manually the 7 to f

Now as required in BIP34 you must include the block height inside the scriptSig otherwise your coinbase transaction will not be valid

PS: Be aware of little and big endian

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.