2

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

1 Answer 1

4

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.

3
  • 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
    Aug 3, 2020 at 22:15
  • 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.
    – Andrew Chow
    Aug 3, 2020 at 23:19
  • 1
    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
    Aug 3, 2020 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.