Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How does one calculate the hash of a Tx? Which fields need to be double SHA hashed and in what order?

share|improve this question
Do you mean the transaction ID hash that the JSON-RPC send* methods return? It can be confusing because hashes for transactions are calculated and signed to transmit bitcoins, but the hashes that are signed are NOT the same as the transaction ID hashes.... – gavinandresen Dec 8 '11 at 3:32
I mean the hashes calculated for the merkle tree, but I suppose both would be useful. – ThePiachu Dec 8 '11 at 11:16
up vote 4 down vote accepted

As explained by Gavin Andersen on the forum - in order to calculate the ID hash of the Tx that is used in the Merkle Tree, one needs to SHA hash the whole Tx message as defined in the Protocol Specification wiki page twice.

For example, for the only Tx from the Genesis Block one would double hash the following array of bytes:


And if double hashed correctly, it would give the following hash:


share|improve this answer

There's a diagram explaining the process of hashing a transaction when creating or verifying the signature of a bitcoin transaction on the forum, and a higher resolution version of the same image on dropbox.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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