<p>The coinbase transaction is a special transaction that has to satisfy the following:</p>
<ol>
<li>Only has 1 input</li>
<li>The input is using <code>0x0000000000000000000000000000000000000000000000000000000000000000</code> as its txid and <code>0xFFFFFFFF</code> as its index (vout)</li>
<li>The signature script of this input has to have a length between 2 and 100 (<code>2&lt;= length &lt;=100</code>)</li>
<li>Any block after BIP-34 activation (height&gt;=227931) must have the block height pushed at the beginning of the signature script using <em>strict</em> push lengths. (The rest of the script is ignored.)</li>
<li>Like any other transaction it has to have <em>at least</em> one output</li>
<li>If the block contained any transaction that had witness, the coinbase tx must have* a single witness (corresponding to its single input) containing a 32 byte witness commitment and an output that contains the computed witness merkle root hash and starts with <code>OP_Return</code> followed by <code>0x24aa21a9ed</code> and is <em>at least</em> 38 bytes total</li>
<li>The sum of output amounts must be smaller than or equal to the block reward + sum of fees</li>
</ol>
<p>*This is optional in case there were no witnesses (so SegWit tx inside the block)</p>

CC BY-SA 4.0
2020-10-16T14:24:46.497Z
2020-10-16T14:24:46.497Z
Coding Enthusiast
<p>I know about</p>
<pre><code>createrawtransaction '[{&quot;txid&quot;:&quot;0000000000000000000000000000000000000000000000000000000000000000&quot;,&quot;vout&quot;:0}]' '{&quot;39jbHRLG6Z2KgXLHR3BWgbccZde1Moo15k&quot;:6.5}' 
</code></pre>
<p>its give</p>
<p>020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff018036be260000000017a914583daf881525ddfcb891e1ab715a2a790b62f03c8700000000</p>
<p>19:10:24
￼</p>
<pre><code>decoderawtransaction 020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff018036be260000000017a914583daf881525ddfcb891e1ab715a2a790b62f03c8700000000

￼
{
  &quot;txid&quot;: &quot;b95321ea560dbdf48581c0ff451699e4240c86021bd10791585b3bc4078681cf&quot;,
  &quot;hash&quot;: &quot;b95321ea560dbdf48581c0ff451699e4240c86021bd10791585b3bc4078681cf&quot;,
  &quot;version&quot;: 2,
  &quot;size&quot;: 83,
  &quot;vsize&quot;: 83,
  &quot;weight&quot;: 332,
  &quot;locktime&quot;: 0,
  &quot;vin&quot;: [
    {
      &quot;txid&quot;: &quot;0000000000000000000000000000000000000000000000000000000000000000&quot;,
      &quot;vout&quot;: 0,
      &quot;scriptSig&quot;: {
        &quot;asm&quot;: &quot;&quot;,
        &quot;hex&quot;: &quot;&quot;
      },
      &quot;sequence&quot;: 4294967295
    }
  ],
  &quot;vout&quot;: [
    {
      &quot;value&quot;: 6.50000000,
      &quot;n&quot;: 0,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;OP_HASH160 583daf881525ddfcb891e1ab715a2a790b62f03c OP_EQUAL&quot;,
        &quot;hex&quot;: &quot;a914583daf881525ddfcb891e1ab715a2a790b62f03c87&quot;,
        &quot;reqSigs&quot;: 1,
        &quot;type&quot;: &quot;scripthash&quot;,
        &quot;addresses&quot;: [
          &quot;39jbHRLG6Z2KgXLHR3BWgbccZde1Moo15k&quot;
        ]
      }
    }
  ]
}
</code></pre>
<p>but if i try decode tx from blockchain
as example tx d56e6eccf09e3b2993326b86d95bf79919ec98ff576c2cc6b550d7fd90187080
from  block 00000000000000000005c8f82be414604a30f33fa35028079d0d012079c8f3ea</p>
<p>￼</p>
<pre><code>getrawtransaction d56e6eccf09e3b2993326b86d95bf79919ec98ff576c2cc6b550d7fd90187080



￼
01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff5b0300f60941d7e1f2e7560aff41d7e1f2e755ef2a2f45324d2026204254432e544f502ffabe6d6d1c3eb14eb586c97d05cb6333184280d0d86e081a6ccc1cbbc0367888f2368b2b8000000000000000e7000a064122000000000000ffffffff0140be4025000000001976a9140b904a4a8590d0ccff680bb8adc4ae4fe49f890a88ac00000000



￼
decoderawtransaction 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff5b0300f60941d7e1f2e7560aff41d7e1f2e755ef2a2f45324d2026204254432e544f502ffabe6d6d1c3eb14eb586c97d05cb6333184280d0d86e081a6ccc1cbbc0367888f2368b2b8000000000000000e7000a064122000000000000ffffffff0140be4025000000001976a9140b904a4a8590d0ccff680bb8adc4ae4fe49f890a88ac00000000



￼
{
  &quot;txid&quot;: &quot;d56e6eccf09e3b2993326b86d95bf79919ec98ff576c2cc6b550d7fd90187080&quot;,
  &quot;hash&quot;: &quot;d56e6eccf09e3b2993326b86d95bf79919ec98ff576c2cc6b550d7fd90187080&quot;,
  &quot;version&quot;: 1,
  &quot;size&quot;: 176,
  &quot;vsize&quot;: 176,
  &quot;weight&quot;: 704,
  &quot;locktime&quot;: 0,
  &quot;vin&quot;: [
    {
      &quot;coinbase&quot;: &quot;0300f60941d7e1f2e7560aff41d7e1f2e755ef2a2f45324d2026204254432e544f502ffabe6d6d1c3eb14eb586c97d05cb6333184280d0d86e081a6ccc1cbbc0367888f2368b2b8000000000000000e7000a064122000000000000&quot;,
      &quot;sequence&quot;: 4294967295
    }
  ],
  &quot;vout&quot;: [
    {
      &quot;value&quot;: 6.25000000,
      &quot;n&quot;: 0,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;OP_DUP OP_HASH160 0b904a4a8590d0ccff680bb8adc4ae4fe49f890a OP_EQUALVERIFY OP_CHECKSIG&quot;,
        &quot;hex&quot;: &quot;76a9140b904a4a8590d0ccff680bb8adc4ae4fe49f890a88ac&quot;,
        &quot;reqSigs&quot;: 1,
        &quot;type&quot;: &quot;pubkeyhash&quot;,
        &quot;addresses&quot;: [
          &quot;1249HZzzG5YSi8juRXPXYopcCYBx3CQYW7&quot;
        ]
      }
    }
  ]
}
</code></pre>
<p>i see coinbase value</p>
<pre><code>&quot;coinbase&quot;: &quot;0300f60941d7e1f2e7560aff41d7e1f2e755ef2a2f45324d2026204254432e544f502ffabe6d6d1c3eb14eb586c97d05cb6333184280d0d86e081a6ccc1cbbc0367888f2368b2b8000000000000000e7000a064122000000000000&quot;,
</code></pre>
<p>what is this ? How to create working coinsbase tx what can be puted to block and it will be correct for mining , all what if find there is not incorrect info and link to outdatet wiki.
tx created by any of that solution dont have this field so they are invalid .</p>
<p>Problem is there no info how to add that coinbase to coinbase tx .</p>
<p>maybe some where exist some python script what can do coinbase tx ? For look at logic how it creation that tx.</p>

<bitcoin-core><blockchain><mining-theory><coinbase-transaction><createrawtransaction>
How to create bitcoin coin , coinbase transaction?
tseries
# How to create bitcoin coin , coinbase transaction?

(Asked by: username_0 on 2020-10-15)

I know about

```
createrawtransaction '[{"txid":"0000000000000000000000000000000000000000000000000000000000000000","vout":0}]' '{"39jbHRLG6Z2KgXLHR3BWgbccZde1Moo15k":6.5}' 

```

its give

020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff018036be260000000017a914583daf881525ddfcb891e1ab715a2a790b62f03c8700000000

19:10:24
￼

```
decoderawtransaction 020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff018036be260000000017a914583daf881525ddfcb891e1ab715a2a790b62f03c8700000000

￼
{
  "txid": "b95321ea560dbdf48581c0ff451699e4240c86021bd10791585b3bc4078681cf",
  "hash": "b95321ea560dbdf48581c0ff451699e4240c86021bd10791585b3bc4078681cf",
  "version": 2,
  "size": 83,
  "vsize": 83,
  "weight": 332,
  "locktime": 0,
  "vin": [
    {
      "txid": "0000000000000000000000000000000000000000000000000000000000000000",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 6.50000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 583daf881525ddfcb891e1ab715a2a790b62f03c OP_EQUAL",
        "hex": "a914583daf881525ddfcb891e1ab715a2a790b62f03c87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "39jbHRLG6Z2KgXLHR3BWgbccZde1Moo15k"
        ]
      }
    }
  ]
}

```

but if i try decode tx from blockchain
as example tx d56e6eccf09e3b2993326b86d95bf79919ec98ff576c2cc6b550d7fd90187080
from block 00000000000000000005c8f82be414604a30f33fa35028079d0d012079c8f3ea

￼

```
getrawtransaction d56e6eccf09e3b2993326b86d95bf79919ec98ff576c2cc6b550d7fd90187080

￼
01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff5b0300f60941d7e1f2e7560aff41d7e1f2e755ef2a2f45324d2026204254432e544f502ffabe6d6d1c3eb14eb586c97d05cb6333184280d0d86e081a6ccc1cbbc0367888f2368b2b8000000000000000e7000a064122000000000000ffffffff0140be4025000000001976a9140b904a4a8590d0ccff680bb8adc4ae4fe49f890a88ac00000000

￼
decoderawtransaction 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff5b0300f60941d7e1f2e7560aff41d7e1f2e755ef2a2f45324d2026204254432e544f502ffabe6d6d1c3eb14eb586c97d05cb6333184280d0d86e081a6ccc1cbbc0367888f2368b2b8000000000000000e7000a064122000000000000ffffffff0140be4025000000001976a9140b904a4a8590d0ccff680bb8adc4ae4fe49f890a88ac00000000

￼
{
  "txid": "d56e6eccf09e3b2993326b86d95bf79919ec98ff576c2cc6b550d7fd90187080",
  "hash": "d56e6eccf09e3b2993326b86d95bf79919ec98ff576c2cc6b550d7fd90187080",
  "version": 1,
  "size": 176,
  "vsize": 176,
  "weight": 704,
  "locktime": 0,
  "vin": [
    {
      "coinbase": "0300f60941d7e1f2e7560aff41d7e1f2e755ef2a2f45324d2026204254432e544f502ffabe6d6d1c3eb14eb586c97d05cb6333184280d0d86e081a6ccc1cbbc0367888f2368b2b8000000000000000e7000a064122000000000000",
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 6.25000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 0b904a4a8590d0ccff680bb8adc4ae4fe49f890a OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9140b904a4a8590d0ccff680bb8adc4ae4fe49f890a88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1249HZzzG5YSi8juRXPXYopcCYBx3CQYW7"
        ]
      }
    }
  ]
}

```

i see coinbase value

```
"coinbase": "0300f60941d7e1f2e7560aff41d7e1f2e755ef2a2f45324d2026204254432e544f502ffabe6d6d1c3eb14eb586c97d05cb6333184280d0d86e081a6ccc1cbbc0367888f2368b2b8000000000000000e7000a064122000000000000",

```

what is this ? How to create working coinsbase tx what can be puted to block and it will be correct for mining , all what if find there is not incorrect info and link to outdatet wiki.
tx created by any of that solution dont have this field so they are invalid .

Problem is there no info how to add that coinbase to coinbase tx .

maybe some where exist some python script what can do coinbase tx ? For look at logic how it creation that tx.

**Tags:** bitcoin-core, blockchain, mining-theory, coinbase-transaction, createrawtransaction


---

## 1 answers

### Answer by username_1 on 2020-10-16. Score: 1

The coinbase transaction is a special transaction that has to satisfy the following:

1. Only has 1 input
2. The input is using `0x0000000000000000000000000000000000000000000000000000000000000000` as its txid and `0xFFFFFFFF` as its index (vout)
3. The signature script of this input has to have a length between 2 and 100 (`2<= length <=100`)
4. Any block after BIP-34 activation (height>=227931) must have the block height pushed at the beginning of the signature script using *strict* push lengths. (The rest of the script is ignored.)
5. Like any other transaction it has to have *at least* one output
6. If the block contained any transaction that had witness, the coinbase tx must have\* a single witness (corresponding to its single input) containing a 32 byte witness commitment and an output that contains the computed witness merkle root hash and starts with `OP_Return` followed by `0x24aa21a9ed` and is *at least* 38 bytes total
7. The sum of output amounts must be smaller than or equal to the block reward + sum of fees

\*This is optional in case there were no witnesses (so SegWit tx inside the block)


---

