0

I have the merkle root, using this value, how to get the block hash or its height? There is this merkle root available in getblock RPC output:

./bitcoin-cli getblock 0320d6c1bd3c4cd2a08d6f76acb50b06a3ed766b058d247fbda3147aecfef388
{
  "tx": [
    "bccf4c873984245694f64263a3392c4d67c6a6f60efe4ed53aa4965f6d8b7dc0"
  ],
  "hash": "0320d6c1bd3c4cd2a08d6f76acb50b06a3ed766b058d247fbda3147aecfef388",
  "confirmations": 2,
  "size": 180,
  "height": 102,
  "version": 536870912,
  "versionHex": "20000000",
  "merkleroot": "bccf4c873984245694f64263a3392c4d67c6a6f60efe4ed53aa4965f6d8b7dc0",
  "num_tx": 1,
  "time": 1593523883,
  "mediantime": 1593467398,
  "nonce": 1,
  "bits": "207fffff",
  "difficulty": 4.656542373906925e-10,
  "chainwork": "00000000000000000000000000000000000000000000000000000000000000ce",
  "previousblockhash": "1664a604a6c8e603e311c6759f7693343ad77896c53de1bcef37de04dbcbbbc5",
  "nextblockhash": "1924c8db1b986f398a12d5481fcc293913a2dab2ee7fbcb0e131d7941e5201c2"
}

using different transaction hashes, I got the merkle root value, now I need to know which block has this merkle root as in getblock.

  • Do you have the entire coinbase transaction? The height is included in its scriptSig – pinhead Jul 1 at 1:37
0

The block hash is the output obtained when hashing the header of a bitcoin block. The header of a bitcoin block is comprised of several pieces of data, one of which is the merkle root.

So having the merkle root alone is not sufficient to calculate the block hash, you would need additional information (the rest of the block header).

You could write some code to query the block database for a specific merkle root, but otherwise I am not aware of any software that currently includes this functionality.

(this seems odd to me though: if you have calculated the merkle root, you assumedly have all the transaction data from the block in question. I'm not sure in what situation you would have all of this data, but not the rest of the block header data)

| improve this answer | |
  • I am in the verge of validating a new functionality of verifying the merkle proof, I used different positions like changing LEFT to RIGHT and got some value of merkle root, hence using that merkle root value, I need to know the block hash / height to verify whether its correct or not. – Bhala T R Jul 1 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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