<p>I would like to hash a block header using terminal commands and look at all the pretty leading 0s, but I can't figure out how to do this correctly using block header data from bitcoin-cli.</p>
<p>Here is what I tried:</p>
<pre><code># get the block header of a recent block and write it to # get the block header of a recent block and write it to blockheader.txt
$ bitcoin-cli getblockheader 0000000000000000000493a92e28a9f9402cef0ff3f953aeca17b506700dfaf9 false &gt; blockheader.txt
# hash it twice
$ sha256sum blockheader.txt &gt; hash1.txt
$ sha256sum hash1.txt
abcaf9cb4c4ea594cdaf330f143f8d5e31fd0539540906149ab0e3d706b7d053  hash1.txt
</code></pre>
<p>As you can see, the output does not match the blockhash input in the first command. What am I doing wrong?</p>

CC BY-SA 4.0
2023-01-09T18:06:28.020Z
Did you check whether `blockheader.txt` has a linebreak at the end, and whether the serialized data actually matches the required input formatting? Might be something like the version needing to be put in low-endian: https://bitcoin.stackexchange.com/a/67792/5406
Murch
CC BY-SA 4.0
2023-01-09T18:08:46.497Z
You're hashing the block header (and the intermediary hash) represented as human-readable text (using the hash encoded in hex). You need to hash the bytes directly.
Pieter Wuille
<bitcoin-cli><sha256><block-header><bash>
How can I hash a block header using bitcoin-cli and terminal commands?
vnprc
# How can I hash a block header using bitcoin-cli and terminal commands?

(Asked by: username_0 on 2023-01-09)

I would like to hash a block header using terminal commands and look at all the pretty leading 0s, but I can't figure out how to do this correctly using block header data from bitcoin-cli.
Here is what I tried:
# get the block header of a recent block and write it to # get the block header of a recent block and write it to blockheader.txt
$ bitcoin-cli getblockheader 0000000000000000000493a92e28a9f9402cef0ff3f953aeca17b506700dfaf9 false > blockheader.txt
# hash it twice
$ sha256sum blockheader.txt > hash1.txt
$ sha256sum hash1.txt
abcaf9cb4c4ea594cdaf330f143f8d5e31fd0539540906149ab0e3d706b7d053  hash1.txt

As you can see, the output does not match the blockhash input in the first command. What am I doing wrong?

**Tags:** bitcoin-cli, sha256, block-header, bash

> **Comments:**
> **username_1**: Did you check whether `blockheader.txt` has a linebreak at the end, and whether the serialized data actually matches the required input formatting? Might be something like the version needing to be put in low-endian: https://bitcoin.stackexchange.com/a/67792/5406  
> **username_2**: You're hashing the block header (and the intermediary hash) represented as human-readable text (using the hash encoded in hex). You need to hash the bytes directly.  

---

## 0 answers

