<p>If the coinbase transaction is the only transaction in a block, then the block's transaction Merkle root is equal to the coinbase transaction's txid.</p>

CC BY-SA 4.0
2021-09-27T14:20:39.003Z
what is txid ? i cant find it on the getblocktemplate wiki . And do i need to hash the coinbase transaction txid or just straight up merkleroot = txid without hash ?
user6668201
CC BY-SA 4.0
2021-09-27T14:38:35.283Z
The txid is the double-SHA256 hash of the serialized transaction. The merkle root is identical to the txid, without any further hashing.
Pieter Wuille
CC BY-SA 4.0
2021-09-27T14:40:20.560Z
Oh thank you ! but i found this on google https://bitcoin.stackexchange.com/questions/97162/merkle-root-with-one-transaction , it says merkle root is equal to the double sha256 of txid0 + txid0 , which one is correct , your answer or the link i just give ? i'm confused
user6668201
CC BY-SA 4.0
2021-09-27T14:42:09.263Z
For the third time: the Merkle root IS the txid, without further hashing. Your link is about the case where you have an odd number of elements in a level, but larger than 1, in order to compute the next level. When a level has only 1 element left, that is the Merkle root. If the coinbase is the only transaction, you already reached the end.
Pieter Wuille
CC BY-SA 4.0
2021-09-27T14:43:15.937Z
So Merkle root = sha256d(txid0 + txid0) is incorrect ?
user6668201
CC BY-SA 4.0
2021-09-27T14:44:36.427Z
No, it is not incorrect, but it doesn't apply here. That is for computing the next level of the Merkle tree when there is an odd number of elements. In your case, there is no next level as you're already done.
Pieter Wuille
CC BY-SA 4.0
2021-09-27T14:45:04.257Z
I'm not trolling , that's literally the accepted answer on other question titled "Merkle root with one transaction" , i'm sorry forgive me i guess i got too confused
user6668201
CC BY-SA 4.0
2021-09-27T14:46:00.300Z
Oh ! that clear it all up ! thank you !
user6668201
CC BY-SA 4.0
2021-09-27T14:46:06.453Z
My apologies, I reacted too quickly. That answer is indeed wrong; it only applies when there is an odd number of elements, but more than 1.
Pieter Wuille
CC BY-SA 4.0
2021-09-27T12:51:41.880Z
2021-09-27T12:51:41.880Z
Pieter Wuille
<p>Based on <a href="https://en.bitcoin.it/wiki/Getblocktemplate" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Getblocktemplate</a> :</p>
<blockquote>
<p>Collect your coinbase transaction (modified or not) at the front of the &quot;transactions&quot; list provided by the server. Apply a double-SHA256 hash to each transaction in the list. Now, as long as the list has more than 1 hash remaining, go through each pair and hash them together. That is, concatenate the first two, double-SHA256 that, repeat for the next two, and so on. If you encounter an odd pair (that is, the hash list ends with a single item and no pairing), concatenate it with itself and hash that. Continue to do that until there is only one hash left: that is your merkle root.</p>
</blockquote>
<p>But what if the block is empty? Since there is no other transaction other than the coinbase transaction, it means there is only one hash.</p>
<p>Is the merkle root of an empty block the double hash of the coinbase transaction? Or do I still need to do something other than double hashing the coinbase?</p>

<merkle-tree><empty-blocks>
Merkle root of empty block
user6668201
# Merkle root of empty block

(Asked by: username_0 on 2021-09-27)

Based on <https://en.bitcoin.it/wiki/Getblocktemplate> :

> Collect your coinbase transaction (modified or not) at the front of the "transactions" list provided by the server. Apply a double-SHA256 hash to each transaction in the list. Now, as long as the list has more than 1 hash remaining, go through each pair and hash them together. That is, concatenate the first two, double-SHA256 that, repeat for the next two, and so on. If you encounter an odd pair (that is, the hash list ends with a single item and no pairing), concatenate it with itself and hash that. Continue to do that until there is only one hash left: that is your merkle root.

But what if the block is empty? Since there is no other transaction other than the coinbase transaction, it means there is only one hash.

Is the merkle root of an empty block the double hash of the coinbase transaction? Or do I still need to do something other than double hashing the coinbase?

**Tags:** merkle-tree, empty-blocks


---

## 1 answers

### Answer by username_1 on 2021-09-27. Score: 3 | Accepted answer

If the coinbase transaction is the only transaction in a block, then the block's transaction Merkle root is equal to the coinbase transaction's txid.

> **Comments:**
> **username_0**: what is txid ? i cant find it on the getblocktemplate wiki . And do i need to hash the coinbase transaction txid or just straight up merkleroot = txid without hash ?  
> **username_1**: The txid is the double-SHA256 hash of the serialized transaction. The merkle root is identical to the txid, without any further hashing.  
> **username_0**: Oh thank you ! but i found this on google https://bitcoin.stackexchange.com/questions/97162/merkle-root-with-one-transaction , it says merkle root is equal to the double sha256 of txid0 + txid0 , which one is correct , your answer or the link i just give ? i'm confused  
> **username_1**: For the third time: the Merkle root IS the txid, without further hashing. Your link is about the case where you have an odd number of elements in a level, but larger than 1, in order to compute the next level. When a level has only 1 element left, that is the Merkle root. If the coinbase is the only transaction, you already reached the end.  
> **username_0**: So Merkle root = sha256d(txid0 + txid0) is incorrect ?  
> **username_1**: No, it is not incorrect, but it doesn't apply here. That is for computing the next level of the Merkle tree when there is an odd number of elements. In your case, there is no next level as you're already done.  
> **username_0**: I'm not trolling , that's literally the accepted answer on other question titled "Merkle root with one transaction" , i'm sorry forgive me i guess i got too confused  
> **username_0**: Oh ! that clear it all up ! thank you !  
> **username_1**: My apologies, I reacted too quickly. That answer is indeed wrong; it only applies when there is an odd number of elements, but more than 1.  

---

