<p>To create a coinbase transaction you need to send this RPC command to your Bitcoin-Qt</p>
<p><code>createrawtransaction '[{&quot;txid&quot;:&quot;0000000000000000000000000000000000000000000000000000000000000000&quot;,&quot;vout&quot;:2147483647}]{&quot;Your Bitcoin Adress&quot;:Amount}'</code></p>
<p>Why <code>2147483647</code> ?</p>
<p>Because the <code>vout</code> must be numeric, and you can't put <code>0xffffffff</code></p>
<p>So this will give you <code>0x7fffffff</code> and the easiest way to do that is to change manually the 7 to f</p>
<p>Now as required in <code>BIP34</code> you must include the block height inside the scriptSig otherwise your coinbase transaction will not be valid</p>
<p>PS: Be aware of little and big endian</p>

CC BY-SA 4.0
2021-05-13T00:52:21.223Z
2021-05-13T00:52:21.223Z
Hamita
<blockquote>
<p>i dont know what to put between the coinbase value and locktime.</p>
</blockquote>
<p>This is the output scriptPubkey, <a href="https://learnmeabitcoin.com/technical/scriptPubKey" rel="nofollow noreferrer">the locking mechanism placed on a transaction output</a>. In the case of a coinbase transaction it should spend the newly minted coins and any transaction fees.</p>
<blockquote>
<p>how does the address convert to hex?</p>
</blockquote>
<p>See <a href="https://bitcoin.stackexchange.com/a/102928/34190">this answer</a></p>
<blockquote>
<p>what OP codes do i need?</p>
</blockquote>
<p>You could use <a href="https://learnmeabitcoin.com/technical/p2pk" rel="nofollow noreferrer">P2PK</a>:</p>
<pre><code>&lt;pub key&gt; OP_CHECKSIG
</code></pre>
<p>or <a href="https://learnmeabitcoin.com/technical/p2pkh" rel="nofollow noreferrer">P2PKH</a>:</p>
<pre><code>OP_DUP OP_HASH160 &lt;RIPEMD160(SHA256(publickey))&gt; OP_EQUALVERIFY OP_CHECKSIG
</code></pre>
<blockquote>
<p>and is this transaction layout correct?</p>
</blockquote>
<p>You could check it against Greg Walker's <a href="https://learnmeabitcoin.com/technical/coinbase-transaction" rel="nofollow noreferrer">learnmeabitcoin</a> coinbase description, or its block explorer:</p>
<p><a href="https://learnmeabitcoin.com/explorer/transaction/json.php?txid=8b50f51b49f27e7bb0efb0b3bf38d12ce4f7e6258b90a75802a394cb585c879d" rel="nofollow noreferrer">https://learnmeabitcoin.com/explorer/transaction/json.php?txid=8b50f51b49f27e7bb0efb0b3bf38d12ce4f7e6258b90a75802a394cb585c879d</a></p>

CC BY-SA 4.0
2023-08-24T10:42:49.817Z
2023-08-24T10:42:49.817Z
Lee
<p>I am creating a miner in C++ for solo mining, and am struggling to create the proper coinbase transaction.</p>
<p>Say I have a bc1 address, like <code>bc1qfc7fameteuguetm0kfzypnvf2ju6wppdvj6tkc</code> , what would be and example of a coinbase transaction with this, and how would I get to it?</p>
<p><a href="https://developer.bitcoin.org/reference/transactions.html" rel="nofollow noreferrer">https://developer.bitcoin.org/reference/transactions.html</a></p>
<pre><code>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
</code></pre>
<p>These are the parts needed to create the data for the transaction.</p>
<p>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?</p>
<p>And then I would then hash it and input it as a new transaction into the block as like so,</p>
<pre><code>tx = {
  &quot;data&quot; : &quot;&lt;hex string mentioned above&gt;&quot;,
  &quot;hash&quot; : &quot;&lt;double sha256 of data above&gt;&quot;,
}
</code></pre>
<p>is that the only data i need for the json?</p>
<p>Thanks in advance.</p>

<hash><miner-configuration><coinbase-transaction>
How to generate a coinbase transaction?
Martin Bradley
# How to generate a coinbase transaction?

(Asked by: username_0 on 2021-02-21)

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.

**Tags:** hash, miner-configuration, coinbase-transaction


---

## 2 answers

### Answer by username_1 on 2021-05-13. Score: 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


---

### Answer by username_2 on 2023-08-24. Score: 0

> i dont know what to put between the coinbase value and locktime.

This is the output scriptPubkey, [the locking mechanism placed on a transaction output](https://learnmeabitcoin.com/technical/scriptPubKey). In the case of a coinbase transaction it should spend the newly minted coins and any transaction fees.

> how does the address convert to hex?

See [this answer](https://bitcoin.stackexchange.com/a/102928/34190)

> what OP codes do i need?

You could use [P2PK](https://learnmeabitcoin.com/technical/p2pk):

```
<pub key> OP_CHECKSIG

```

or [P2PKH](https://learnmeabitcoin.com/technical/p2pkh):

```
OP_DUP OP_HASH160 <RIPEMD160(SHA256(publickey))> OP_EQUALVERIFY OP_CHECKSIG

```

> and is this transaction layout correct?

You could check it against Greg Walker's [learnmeabitcoin](https://learnmeabitcoin.com/technical/coinbase-transaction) coinbase description, or its block explorer:

<https://learnmeabitcoin.com/explorer/transaction/json.php?txid=8b50f51b49f27e7bb0efb0b3bf38d12ce4f7e6258b90a75802a394cb585c879d>


---

