<p>It is not possible to create a coinbase transaction using <code>createrawtransaction</code>. There are numerous rules that coinbase transactions must follow that the <code>createrawtransaction</code> RPC does not have the ability to set the fields to meet those rules. For example, BIP 34 requires the coinbase contain the block's height in the scriptSig. However <code>createrawtransaction</code> does not allow you to set the anything in the scriptSig.</p>
<p>Miners must use software that can independently create the coinbase transaction. Miners actually prefer doing this because they want to be able to modify the coinbase to use as an extra nonce so that when they run out of nonces, they don't necessarily have to re-select the transactions to include in the block. Instead they can change the coinbase to cause the merkle root to change.</p>

CC BY-SA 4.0
2020-12-31T19:10:33.670Z
2020-12-31T19:10:33.670Z
Ava Chow
<p>According to BIP 34, you must include the block Height to your Coinbase transaction, otherwise, it will be invalid,</p>
<p>The scryptSig of your coinbase transaction, must begin with number of pushed bytes (Actually is 0x03) and then the hex representation of your candidate block, dont forget the little endian conversion</p>

CC BY-SA 4.0
2020-08-03T18:10:36.877Z
2020-08-03T18:10:36.877Z
Hamita
<p>I recommend looking over this code in python which will illustrate how the coinbase is constructed, it is the simplest example I can think of, and is commented well - <a href="https://github.com/vsergeev/ntgbtminer/blob/master/ntgbtminer.py#L166" rel="nofollow noreferrer">https://github.com/vsergeev/ntgbtminer/blob/master/ntgbtminer.py#L166</a></p>

CC BY-SA 4.0
2023-10-27T12:29:50.363Z
2023-10-27T12:29:50.363Z
Amrita Bithi
<p>I would like to generate a transaction with <code>createrawtransaction</code> such that it can be passed to <code>submitblock</code> along with the block header.</p>
<p>I tried to use:</p>
<pre><code>[{&quot;txid&quot;:&quot;0000000000000000000000000000000000000000000000000000000000000000&quot;,&quot;vout&quot;:0}]{&quot;bc1qd8hza5w3mz7t3tudtlplm9xht4sjwg0e3t9gy2&quot;:6.25000000}
</code></pre>
<p>but it's not outputting a coinbase transaction:</p>
<pre><code>020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0140be40250000000016001469ee2ed1d1d8bcb8af8d5fc3fd94d75d612721f900000000
</code></pre>

CC BY-SA 4.0
2020-07-18T11:02:25.407Z
How is that not a coinbase? The null input is the key characteristic.
pinhead
CC BY-SA 4.0
2020-07-18T12:06:49.520Z
i was test it with fresh blockchain with 100% valid block , with  markle root from this tx , submitblock was no accept it and say "Block does not start with a coinbase (code -22)"
tseries
CC BY-SA 4.0
2020-07-18T12:08:58.577Z
there are also other coinbase rules as well such as bip34 height in scriptSig.
pinhead
CC BY-SA 4.0
2020-07-18T12:15:39.637Z
ok, but how add them for make coinbase valid for submit  block ?  a dont see any other rules at createrawtransaction help.
tseries
CC BY-SA 4.0
2020-07-18T12:17:17.613Z
Oh I see one more thing -- the vout for coinbase input should be `0xffffffff` not `0`
pinhead
CC BY-SA 4.0
2020-07-18T12:21:16.053Z
yes , and how do this no answers , maybe it imposible do at console . 
but if avaliable command submitblock and submitheader, most exist somting for create coinbase tx.
tseries
CC BY-SA 4.0
2020-07-18T13:51:47.793Z
You're so close, just try "vout": 4294967295 instead of 0
pinhead
CC BY-SA 4.0
2020-07-18T16:04:04.890Z
to not work , it say's our of range...
tseries
<bitcoin-core><transactions><coinbase-transaction>
How create coinbase transaction with createrawtransaction?
tseries
# How create coinbase transaction with createrawtransaction?

(Asked by: username_0 on 2020-07-18)

I would like to generate a transaction with createrawtransaction such that it can be passed to submitblock along with the block header.
I tried to use:
[{"txid":"0000000000000000000000000000000000000000000000000000000000000000","vout":0}]{"bc1qd8hza5w3mz7t3tudtlplm9xht4sjwg0e3t9gy2":6.25000000}

but it's not outputting a coinbase transaction:
020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0140be40250000000016001469ee2ed1d1d8bcb8af8d5fc3fd94d75d612721f900000000

**Tags:** bitcoin-core, transactions, coinbase-transaction

> **Comments:**
> **username_1**: How is that not a coinbase? The null input is the key characteristic.  
> **username_0**: i was test it with fresh blockchain with 100% valid block , with  markle root from this tx , submitblock was no accept it and say "Block does not start with a coinbase (code -22)"  
> **username_1**: there are also other coinbase rules as well such as bip34 height in scriptSig.  
> **username_0**: ok, but how add them for make coinbase valid for submit  block ?  a dont see any other rules at createrawtransaction help.  
> **username_1**: Oh I see one more thing -- the vout for coinbase input should be `0xffffffff` not `0`  
> **username_0**: yes , and how do this no answers , maybe it imposible do at console .  but if avaliable command submitblock and submitheader, most exist somting for create coinbase tx.  
> **username_1**: You're so close, just try "vout": 4294967295 instead of 0  
> **username_0**: to not work , it say's our of range...  

---

## 3 answers

### Answer by username_2 on 2020-12-31. Score: 3

It is not possible to create a coinbase transaction using `createrawtransaction`. There are numerous rules that coinbase transactions must follow that the `createrawtransaction` RPC does not have the ability to set the fields to meet those rules. For example, BIP 34 requires the coinbase contain the block's height in the scriptSig. However `createrawtransaction` does not allow you to set the anything in the scriptSig.

Miners must use software that can independently create the coinbase transaction. Miners actually prefer doing this because they want to be able to modify the coinbase to use as an extra nonce so that when they run out of nonces, they don't necessarily have to re-select the transactions to include in the block. Instead they can change the coinbase to cause the merkle root to change.


---

### Answer by username_3 on 2020-08-03. Score: 1

According to BIP 34, you must include the block Height to your Coinbase transaction, otherwise, it will be invalid,

The scryptSig of your coinbase transaction, must begin with number of pushed bytes (Actually is 0x03) and then the hex representation of your candidate block, dont forget the little endian conversion


---

### Answer by username_4 on 2023-10-27. Score: 0

I recommend looking over this code in python which will illustrate how the coinbase is constructed, it is the simplest example I can think of, and is commented well - <https://github.com/vsergeev/ntgbtminer/blob/master/ntgbtminer.py#L166>


---

