<p>In this transaction, the scriptSig is of size 0 because it isn't filled out yet. You have also used a txid of all 0's and a vout of 0, so this size of 0 gets lost in your large string of zeroes.</p>
<p><code>00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff</code> is the input data.</p>
<p>The first 32 bytes of this is the previous txid. The 4 bytes following that is the vout. This leaves us with <code>00ffffffff</code>. That remaining <code>0x00</code> byte is the length of the scriptSig, currently length 0. The <code>ffffffff</code> is the sequence number.</p>
<p>What you have to do is replace that 0x00 byte with your scriptSig. The scriptSig is prepended by it's length, so what you replace that with would look like <code>040334cc09</code>.</p>
<p>Note that currently your transaction would not be a valid coinbase transaction. The vout for a coinbase transaction is <code>0xffffffff</code>, not 0.</p>

CC BY-SA 4.0
2020-08-03T22:15:22.083Z
Thank you for your answer, but when i try the `ffffffff` in the vout, it gives an error, and in the documentation it says the vout value must be numeric, how it can accept a hex value?
Hamita
CC BY-SA 4.0
2020-08-03T23:19:44.970Z
You can't. It doesn't accept it as hex and both 4294967295 and -2147483647 are not accepted (the former is too large, the latter is negative which isn't allowed). You will have to modify the raw transaction to contain this value. The easiest way to do this is to use 2147483647 as the vout. This will give it a vout of `0x7fffffff` (in little endian so it will be `ffffff7f`). Then just change that `7` to `f` manually.
Ava Chow
CC BY-SA 4.0
2020-08-03T23:35:40.533Z
Yes, that's great, i put 2147483647 as the vout and it gives me this: `020000000100000000000...0000000000ffffff7f00ffffffff0140be4025000000001600140f3be243717c5bb903666c2de78c55d632e8e8a500000000`, i changed the `7` to `f`, then added the scriptsig prepended by it's length so it become `0200000001000000000000000000000000000...00000000000000000000000ffffffff` + `0403` + `Block height` + `ffffffff0140be4025000000001600140f3be243717c5bb903666c2de78c55d632e8e8a500000000` and now it become a valid coinbase transaction
Hamita
CC BY-SA 4.0
2020-08-03T21:30:44.297Z
2020-08-03T21:30:44.297Z
Ava Chow
<p>I created a coinbase transaction with the createrawtransaction method as follow:</p>
<p><code>createrawtransaction '[{&quot;txid&quot;:&quot;0000000000000000000000000000000000000000000000000000000000000000&quot;,&quot;vout&quot;:0}]{&quot;kgjdtruea5w3mz7t3tudtlplm9xht4sjwg0e3tihgtr&quot;:6.25000000}'</code></p>
<p>the response to this call is:</p>
<pre><code>020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0140be40250000000017a9145ea405d95b789aa887e229d8b1da44c2964054248700000000

</code></pre>
<p>I understand that the number of pushed bytes and the Height of the block must be included to the scriptsig of this raw data as follow:</p>
<p>Actually <code>03</code> + <code>The height of the block in little endian</code></p>
<p>In this exemple must i put this just between the <code>ffffffff</code> and  <code>0140be40250000</code>?</p>
<p>I saw some exemples but i am confused, as there's the size of the scriptsig before the scryptsig</p>
<p>Help is appreciated</p>
<p>Thank you to all of you</p>

<coinbase-transaction><bip-34>
As required in BIP 34, how miners put the Block Height to their coinbase transaction
Hamita
# As required in BIP 34, how miners put the Block Height to their coinbase transaction

(Asked by: username_0 on 2020-08-03)

I created a coinbase transaction with the createrawtransaction method as follow:

`createrawtransaction '[{"txid":"0000000000000000000000000000000000000000000000000000000000000000","vout":0}]{"kgjdtruea5w3mz7t3tudtlplm9xht4sjwg0e3tihgtr":6.25000000}'`

the response to this call is:

```
020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0140be40250000000017a9145ea405d95b789aa887e229d8b1da44c2964054248700000000

```

I understand that the number of pushed bytes and the Height of the block must be included to the scriptsig of this raw data as follow:

Actually `03` + `The height of the block in little endian`

In this exemple must i put this just between the `ffffffff` and `0140be40250000`?

I saw some exemples but i am confused, as there's the size of the scriptsig before the scryptsig

Help is appreciated

Thank you to all of you

**Tags:** coinbase-transaction, bip-34


---

## 1 answers

### Answer by username_1 on 2020-08-03. Score: 4 | Accepted answer

In this transaction, the scriptSig is of size 0 because it isn't filled out yet. You have also used a txid of all 0's and a vout of 0, so this size of 0 gets lost in your large string of zeroes.

`00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff` is the input data.

The first 32 bytes of this is the previous txid. The 4 bytes following that is the vout. This leaves us with `00ffffffff`. That remaining `0x00` byte is the length of the scriptSig, currently length 0. The `ffffffff` is the sequence number.

What you have to do is replace that 0x00 byte with your scriptSig. The scriptSig is prepended by it's length, so what you replace that with would look like `040334cc09`.

Note that currently your transaction would not be a valid coinbase transaction. The vout for a coinbase transaction is `0xffffffff`, not 0.

> **Comments:**
> **username_0**: Thank you for your answer, but when i try the `ffffffff` in the vout, it gives an error, and in the documentation it says the vout value must be numeric, how it can accept a hex value?  
> **username_1**: You can't. It doesn't accept it as hex and both 4294967295 and -2147483647 are not accepted (the former is too large, the latter is negative which isn't allowed). You will have to modify the raw transaction to contain this value. The easiest way to do this is to use 2147483647 as the vout. This will give it a vout of `0x7fffffff` (in little endian so it will be `ffffff7f`). Then just change that `7` to `f` manually.  
> **username_0**: Yes, that's great, i put 2147483647 as the vout and it gives me this: `020000000100000000000...0000000000ffffff7f00ffffffff0140be4025000000001600140f3be243717c5bb903666c2de78c55d632e8e8a500000000`, i changed the `7` to `f`, then added the scriptsig prepended by it's length so it become `0200000001000000000000000000000000000...00000000000000000000000ffffffff` + `0403` + `Block height` + `ffffffff0140be4025000000001600140f3be243717c5bb903666c2de78c55d632e8e8a500000000` and now it become a valid coinbase transaction  

---

