<p>Whenever data is serialized to bytes in Bitcoin, the bytes are represented in little endian. (Data that is already in bytes does not need to be serialized or otherwise converted.)</p>
<p>When there is only a single element in the merkle tree, the root of the tree is the hash of that element. Therefore, you would only need to serialize the coinbase transaction and hash the bytes resulting from the serialization. The resulting hash is the coinbase's txid as well as the merkle root.</p>

CC BY-SA 4.0
2020-07-24T18:14:27.590Z
ah, thank you, i thought we do this when it's an odd number of transactions, and according to the documentation, it says when it contains only the coinbase transaction, the merkle root will be the same
Hamita
CC BY-SA 4.0
2020-07-24T18:01:04.730Z
2021-09-27T15:14:28.243Z
2021-09-27T15:14:28.243Z
Murch
<p>I put the answer for my question here, if someone else need it, the right answer is:
Convert before hashing and after hashing</p>

CC BY-SA 4.0
2020-07-24T18:48:17.540Z
2020-07-24T18:48:17.540Z
Hamita
<p>I am trying to build a merkle root which contains only the <code>coinbase transaction</code> from <code>bitcoind</code>.</p>
<p>After creating the <code>coinbase transaction</code>, do I need to convert it to <code>little endian</code>, hash it twice and then put it in the <code>blockheader</code> as it is, or do I have to it reconvert it again before I put it in the <code>blockheader</code>?</p>
<p>I mean:</p>
<p>step 1: convert <code>coinbase transaction</code> to <code>little endian</code><br />
step 2: double <code>SHA256</code><br />
step 3: reconvert to <code>little endian</code> or let it as it's?<br />
step 4: put it on the <code>blockheader</code></p>
<p>I am a little confused</p>
<p>Thank you for help</p>

<coinbase-transaction><merkle-tree><block-header><empty-blocks>
Merkle root with one transaction
Hamita
# Merkle root with one transaction

(Asked by: username_0 on 2020-07-24)

I am trying to build a merkle root which contains only the `coinbase transaction` from `bitcoind`.

After creating the `coinbase transaction`, do I need to convert it to `little endian`, hash it twice and then put it in the `blockheader` as it is, or do I have to it reconvert it again before I put it in the `blockheader`?

I mean:

step 1: convert `coinbase transaction` to `little endian`  
step 2: double `SHA256`  
step 3: reconvert to `little endian` or let it as it's?  
step 4: put it on the `blockheader`

I am a little confused

Thank you for help

**Tags:** coinbase-transaction, merkle-tree, block-header, empty-blocks


---

## 2 answers

### Answer by username_1 on 2020-07-24. Score: 2 | Accepted answer

Whenever data is serialized to bytes in Bitcoin, the bytes are represented in little endian. (Data that is already in bytes does not need to be serialized or otherwise converted.)

When there is only a single element in the merkle tree, the root of the tree is the hash of that element. Therefore, you would only need to serialize the coinbase transaction and hash the bytes resulting from the serialization. The resulting hash is the coinbase's txid as well as the merkle root.

> **Comments:**
> **username_0**: ah, thank you, i thought we do this when it's an odd number of transactions, and according to the documentation, it says when it contains only the coinbase transaction, the merkle root will be the same  

---

### Answer by username_0 on 2020-07-24. Score: 0

I put the answer for my question here, if someone else need it, the right answer is:
Convert before hashing and after hashing


---

