<p>The coinbase transaction is constructed by the miner/mining pool operator and is not a transaction which can be broadcast to the mempool.</p>

<p>The amount of the coinbase output is strictly according to the block height, which begins with 50 BTC and halves every 150 blocks in regtest mode. When you create a new block in regtest mode, it will automatically generate a coinbase transaction, with the output spending to your specified coinbase wallet.</p>

<p>The input script of the coinbase has the [blockheight (4B)] and additional data, totally a maximum of 100B.</p>

<p><strong>Input:</strong></p>

<ul>
<li>Previous TX hash: <code>00..00</code></li>
<li>Previous output index: <code>max_value(ff..ff)</code></li>
<li>Input script: <code>[blockheight (4B)] [additional arbitrary data]</code></li>
</ul>

<p>The input is not signed because it does not spend from a UTXO. There are no locking conditions other than to be committed to a header with valid POW.</p>

CC BY-SA 4.0
2021-08-01T05:48:46.243Z
why are there scriptPubKey's in vout's of coinbase transactions?
Joe
CC BY-SA 4.0
2021-08-02T12:31:56.010Z
The scriptPubKey in coinbase vouts indicate the spending conditions of the mining reward: this way, the miner can indicate who can spend the mining fees/minted coins.
James C.
CC BY-SA 4.0
2019-02-04T16:53:27.420Z
2019-02-04T16:53:27.420Z
James C.
<p>I am trying to build a coinbase for mining with the following steps:</p>

<p>1-Create dummy Input and output.</p>

<p>2-Pass them to CreateRawTransaction as collection/</p>

<p>3-Get a transaction back and fill the empty fields according to coinbase structure (specially set Txout’s Value to 12.5 bitcoin).</p>

<p>4-Serialized transaction into Hex string mode.</p>

<p>With above steps preformed in RegTest mode a new block created and 50 Bitcoins added to the wallet which seems to be correct but as far as I know a transaction should be signed, Is Coinbase excluded from signing procedure ? and why it’s add 50 bitcoins to account instead of amount which I specific set to 12.5 bitcoin ?</p>

<hr>

<pre><code>public async Task&lt;string&gt; BuildCoinbaseTransaction(string MinerAddress, uint Height)    
{    
    string coinTxSerialized = string.Empty;    
    scriptData = Tools.RandomNumbers(rEngine);    
    string pubKey = await GetPublicKey(MinerAddress);    
    string scriptPubKey = CreateCoinbaseScript(pubKey);

    List&lt;object&gt; txi = new List&lt;object&gt;
    { new CoinIn { TxId = "0".PadLeft(64, '0'), Index = 0x0 } };

    List&lt;object&gt; txo = new List&lt;object&gt;
      { new Dictionary&lt;string, double&gt; { { MinerAddress, 0.00 } } };

    RPCResult&lt;string&gt; rpcResult = await cmd.CreateRawTransactionAsync(txi, txo);

    if (rpcResult.Error == null)    
    {    
        TotalReward = Math.Min(RewardCoins + CollectedFee, MaxCoinbaseValue);    

        string rawCoinbase = rpcResult.Result;        
        string decodedTx = await cmd.DecodeRawTransaction_CommandAsync(rawCoinbase);

        RPCResult&lt;string&gt; Transaction jsonTx= JsonConvert.DeserializeObject&lt;RPCResult&lt;string&gt;&gt;(decodedTx);    
        Transaction coinTx = jsonTx.Result;

        coinTx.Height = BuildHeight(Height);    
        coinTx.TxIn.FirstOrDefault().Coinbase = scriptData;    
        coinTx.TxIn.FirstOrDefault().Sequence = 0xFFFFFFFF;    
        coinTx.TxOut.FirstOrDefault().Value = TotalReward;    
        coinTx.TxOut.FirstOrDefault().ScriptPubKey.Assembely = scriptPubKey;    
        coinTx.Hex = coinTx.ToString();    
        coinTxSerialized = coinTx.Hex;    

        return coinTxSerialized;    
   }//if

}//BuildCoinbaseTransaction
</code></pre>

<coinbase-transaction>
Is Coinbase transaction required to be signed?
Ali Harsini
# Is Coinbase transaction required to be signed?

(Asked by: username_0 on 2019-02-04)

I am trying to build a coinbase for mining with the following steps:

1-Create dummy Input and output.

2-Pass them to CreateRawTransaction as collection/

3-Get a transaction back and fill the empty fields according to coinbase structure (specially set Txout’s Value to 12.5 bitcoin).

4-Serialized transaction into Hex string mode.

With above steps preformed in RegTest mode a new block created and 50 Bitcoins added to the wallet which seems to be correct but as far as I know a transaction should be signed, Is Coinbase excluded from signing procedure ? and why it’s add 50 bitcoins to account instead of amount which I specific set to 12.5 bitcoin ?

---

```
public async Task<string> BuildCoinbaseTransaction(string MinerAddress, uint Height)    
{    
    string coinTxSerialized = string.Empty;    
    scriptData = Tools.RandomNumbers(rEngine);    
    string pubKey = await GetPublicKey(MinerAddress);    
    string scriptPubKey = CreateCoinbaseScript(pubKey);

    List<object> txi = new List<object>
    { new CoinIn { TxId = "0".PadLeft(64, '0'), Index = 0x0 } };

    List<object> txo = new List<object>
      { new Dictionary<string, double> { { MinerAddress, 0.00 } } };

    RPCResult<string> rpcResult = await cmd.CreateRawTransactionAsync(txi, txo);

    if (rpcResult.Error == null)    
    {    
        TotalReward = Math.Min(RewardCoins + CollectedFee, MaxCoinbaseValue);    

        string rawCoinbase = rpcResult.Result;        
        string decodedTx = await cmd.DecodeRawTransaction_CommandAsync(rawCoinbase);

        RPCResult<string> Transaction jsonTx= JsonConvert.DeserializeObject<RPCResult<string>>(decodedTx);    
        Transaction coinTx = jsonTx.Result;

        coinTx.Height = BuildHeight(Height);    
        coinTx.TxIn.FirstOrDefault().Coinbase = scriptData;    
        coinTx.TxIn.FirstOrDefault().Sequence = 0xFFFFFFFF;    
        coinTx.TxOut.FirstOrDefault().Value = TotalReward;    
        coinTx.TxOut.FirstOrDefault().ScriptPubKey.Assembely = scriptPubKey;    
        coinTx.Hex = coinTx.ToString();    
        coinTxSerialized = coinTx.Hex;    

        return coinTxSerialized;    
   }//if

}//BuildCoinbaseTransaction

```

**Tags:** coinbase-transaction


---

## 1 answers

### Answer by username_1 on 2019-02-04. Score: 1 | Accepted answer

The coinbase transaction is constructed by the miner/mining pool operator and is not a transaction which can be broadcast to the mempool.

The amount of the coinbase output is strictly according to the block height, which begins with 50 BTC and halves every 150 blocks in regtest mode. When you create a new block in regtest mode, it will automatically generate a coinbase transaction, with the output spending to your specified coinbase wallet.

The input script of the coinbase has the [blockheight (4B)] and additional data, totally a maximum of 100B.

**Input:**

* Previous TX hash: `00..00`
* Previous output index: `max_value(ff..ff)`
* Input script: `[blockheight (4B)] [additional arbitrary data]`

The input is not signed because it does not spend from a UTXO. There are no locking conditions other than to be committed to a header with valid POW.

> **Comments:**
> **username_2**: why are there scriptPubKey's in vout's of coinbase transactions?  
> **username_1**: The scriptPubKey in coinbase vouts indicate the spending conditions of the mining reward: this way, the miner can indicate who can spend the mining fees/minted coins.  

---

