<p>I found the solution myself. Block explorers, for some reason, displays TXIDs in reversed form, so you need to unreverse it before using.</p>
<p>I didn't calculate TXIDs manually, I just took them from the mempool.space, so my calculation of Merkle root went wrong. I just needed to calculate TXIDs myself or to reverse the values presented there.</p>
<p>Thanks to <em>Vojtěch Strnad</em>.</p>

CC BY-SA 4.0
2023-11-28T00:37:37.860Z
The TXID is a hash, not a number, so the concept of endianness doesn't really apply here. However, it is normally presented in reverse order (it's not completely clear why Satoshi did it this way), so you have to unreverse it before doing calculations with it.
Vojtěch Strnad
CC BY-SA 4.0
2023-11-28T01:25:07.857Z
@VojtěchStrnad I assume that he wanted to present everything in the same "reversed" way (little endian) regardless of whether it is a number or not.
Cosmos
CC BY-SA 4.0
2023-11-28T01:38:00.470Z
@VojtěchStrnad No, I do not need to "unreverse" it. I must keep it reversed. So after calculating a TXID, it is necessary to reverse it. Mempool.space is showing as it is (without reversing).
Cosmos
CC BY-SA 4.0
2023-11-28T02:14:58.213Z
You are right, you confused me with this "`However, it is normally presented in reverse order (it's not completely clear why Satoshi did it this way)...`. I assumed you are talking about the way we are calculating merkle tree (since you mentioned Satoshi) and not the way it is represented in Block explorers. In block explorers it is presented in reversed form and when we are calculating merkle tree we are using "normal" form.
Cosmos
CC BY-SA 4.0
2023-11-28T00:33:36.127Z
2023-11-28T02:21:26.167Z
2023-11-28T02:21:26.167Z
Cosmos
<p>I want to learn how to calculate the Merkle root so I started from a simple example, a block with only 2 transactions (<a href="https://mempool.space/block/000000000001f657aad04f95503e76a6ee02641deea87721de00d34ad3a9f8e8?showDetails=true&amp;view=actual#details" rel="nofollow noreferrer">block #99997</a>). However, I ran into a problem.</p>
<p>Mempool online block explorer says that the Merkle root of this block is: <code>5140e5972f672bf8e81bc189894c55a410723b095716eaeec845490aed785f0e</code>.</p>
<p>However, I am getting the different value.</p>
<p>Two transactions are contained inside the block #99997 and their TXID are:</p>
<ul>
<li><p><code>b86f5ef1da8ddbdb29ec269b535810ee61289eeac7bf2b2523b494551f03897c</code></p>
</li>
<li><p><code>80c6f121c3e9fe0a59177e49874d8c703cbadee0700a782e4002e87d862373c6</code></p>
</li>
</ul>
<p>I did the following steps:</p>
<ol>
<li>concatenation of transaction IDs<br />
(result:<code>b86f5ef1da8ddbdb29ec269b535810ee61289eeac7bf2b2523b494551f03897c80c6f121c3e9fe0a59177e49874d8c703cbadee0700a782e4002e87d862373c6</code>)</li>
<li>SHA256 of the result from the step 1 (result:<code>e08d8ecc5a02b113bea1e7e2786b8235ddb5ab6058910f30b4d966b30e484bda</code>)</li>
<li>SHA256 of the result from the step 2 (result:<code>5ab58ee21a1ae7476d59e6b7ddb05a80e8b42a4bf5748e9c5db9eb860b2bd040</code>)</li>
</ol>
<p>As you can see I got the different value for the Merkle root than the one presented on the Mempool site.</p>
<p>Mine: <code>5ab58ee21a1ae7476d59e6b7ddb05a80e8b42a4bf5748e9c5db9eb860b2bd040</code></p>
<p>Their: <code>5140e5972f672bf8e81bc189894c55a410723b095716eaeec845490aed785f0e</code></p>
<p>What am I doing wrong?</p>

<merkle-tree>
What am I doing wrong in calculating Merkle root of the block with only 2 transactions (block #99997)?
Cosmos
# What am I doing wrong in calculating Merkle root of the block with only 2 transactions (block #99997)?

(Asked by: username_0 on 2023-11-27)

I want to learn how to calculate the Merkle root so I started from a simple example, a block with only 2 transactions ([block #99997](https://mempool.space/block/000000000001f657aad04f95503e76a6ee02641deea87721de00d34ad3a9f8e8?showDetails=true&view=actual#details)). However, I ran into a problem.

Mempool online block explorer says that the Merkle root of this block is: `5140e5972f672bf8e81bc189894c55a410723b095716eaeec845490aed785f0e`.

However, I am getting the different value.

Two transactions are contained inside the block #99997 and their TXID are:

* `b86f5ef1da8ddbdb29ec269b535810ee61289eeac7bf2b2523b494551f03897c`
* `80c6f121c3e9fe0a59177e49874d8c703cbadee0700a782e4002e87d862373c6`

I did the following steps:

1. concatenation of transaction IDs  
   (result:`b86f5ef1da8ddbdb29ec269b535810ee61289eeac7bf2b2523b494551f03897c80c6f121c3e9fe0a59177e49874d8c703cbadee0700a782e4002e87d862373c6`)
2. SHA256 of the result from the step 1 (result:`e08d8ecc5a02b113bea1e7e2786b8235ddb5ab6058910f30b4d966b30e484bda`)
3. SHA256 of the result from the step 2 (result:`5ab58ee21a1ae7476d59e6b7ddb05a80e8b42a4bf5748e9c5db9eb860b2bd040`)

As you can see I got the different value for the Merkle root than the one presented on the Mempool site.

Mine: `5ab58ee21a1ae7476d59e6b7ddb05a80e8b42a4bf5748e9c5db9eb860b2bd040`

Their: `5140e5972f672bf8e81bc189894c55a410723b095716eaeec845490aed785f0e`

What am I doing wrong?

**Tags:** merkle-tree


---

## 1 answers

### Answer by username_0 on 2023-11-28. Score: 1

I found the solution myself. Block explorers, for some reason, displays TXIDs in reversed form, so you need to unreverse it before using.

I didn't calculate TXIDs manually, I just took them from the mempool.space, so my calculation of Merkle root went wrong. I just needed to calculate TXIDs myself or to reverse the values presented there.

Thanks to *username_1*.

> **Comments:**
> **username_1**: The TXID is a hash, not a number, so the concept of endianness doesn't really apply here. However, it is normally presented in reverse order (it's not completely clear why Satoshi did it this way), so you have to unreverse it before doing calculations with it.  
> **username_0**: @username_1 I assume that he wanted to present everything in the same "reversed" way (little endian) regardless of whether it is a number or not.  
> **username_0**: @username_1 No, I do not need to "unreverse" it. I must keep it reversed. So after calculating a TXID, it is necessary to reverse it. Mempool.space is showing as it is (without reversing).  
> **username_0**: You are right, you confused me with this "`However, it is normally presented in reverse order (it's not completely clear why Satoshi did it this way)...`. I assumed you are talking about the way we are calculating merkle tree (since you mentioned Satoshi) and not the way it is represented in Block explorers. In block explorers it is presented in reversed form and when we are calculating merkle tree we are using "normal" form.  

---

