After creation, what I have to do with a coinbase transaction?

0

I have create a coinbase transaction successfully with the command:

createrawtransaction '[{"txid":"0000000000000000000000000000000000000000000000000000000000000000","vout":0}]' '{"12Evb28oMpkP76HRS2CZ7VjNMD25B84VMv":12.5}'

what give a hex string for the transaction. But when I try signrawtransaction I got this error:

{
  "hex": "...",
  "complete": false,
  "errors": [
    {
      "txid": "0000000000000000000000000000000000000000000000000000000000000000",
      "vout": 0,
      "scriptSig": "",
      "sequence": ...,
      "error": "Input not found or already spent"
    }
  ]
}

with sendrawtransactions i got:

Missing inputs (code -25)

what I have to do with this transaction after create it?

Kleber Mota

Posted 2017-08-27T13:44:31.633

Reputation: 131

Answers

1

A coinbase transaction is not one that is signed or broadcast to the network. Rather it should be the first transaction in the block that you are mining. Also, the first 4 bytes of the scriptSig must be the block's height (1 byte for pushdata 3 bytes for the height).

Andrew Chow

Posted 2017-08-27T13:44:31.633

Reputation: 40 910

The result for the command createrawtransaction above is a hex string. FOr create the block I want broadcast, I think I need a transaction id (txid)? Or am I mistaken? If I am not, how I get the txid for the coinbase transaction?Kleber Mota 2017-08-27T16:22:28.127

1The txid is the hash of the bytes of the transaction, so you first need to make the hexstring an array of bytes and then hash that with sha256d. The block also contains that transaction, not the txid (the txid is only part of the merkle root), so your block, when you broadcast it, must also contain the transaction itself.Andrew Chow 2017-08-27T16:39:29.477

Do you know how to pack the transaction to append to the block? Just create a array with each field and then hash it with sha256d?Kleber Mota 2017-08-27T23:47:03.180

The hash is not included in the block. It is only used for creating the merkle root. The transaction is the hex string that createrawtransaction gives you. You will need to slightly modify it. That hex string is a string representation of the bytes, so you will need to convert it into an array of bytes. Every two characters is one byte.Andrew Chow 2017-08-28T01:13:04.177

Not the coinbase transaction, I mean. How pack the transactionS into the block: the ones returned by the getblocktemplate command. I already know how to retrieve the data from the json-rpc interface. For calculate the merkle root, I create an array with all txid's. What other data available I need to use to build de list of transactions for the new block?Kleber Mota 2017-08-28T02:17:57.673

1You just need the hex of the transaction which you can get by using getrawtransaction.Andrew Chow 2017-08-28T03:24:56.990