<p>You can make it with <a href="https://en.bitcoin.it/wiki/Protocol_documentation#getheaders" rel="nofollow noreferrer">getheaders</a> p2p message, will return headers of blocks in a range.<br />
Remember of <a href="https://en.bitcoin.it/wiki/Protocol_documentation#version" rel="nofollow noreferrer">handshaking</a> and setting tx-relay to false.</p>

CC BY-SA 4.0
2022-01-16T23:47:20.750Z
Thanks! This is what I'm looking for. Is there a C++ library that could handle sending/receiving the data?
user491880
CC BY-SA 4.0
2022-01-16T23:44:59.547Z
2022-01-16T23:44:59.547Z
Davidson Souza
<p>A procedure for doing this using <a href="https://electrum.org/" rel="nofollow noreferrer">Electrum</a> 4.5.5 on Ubuntu:</p>
<ol>
<li><p>Download the Electrum Python code (from here; <a href="https://electrum.org/#download" rel="nofollow noreferrer">https://electrum.org/#download</a>
) and save to <code>/your/path/electrum455</code></p>
</li>
<li><p>Ensure you have the necessary dependencies (consult <code>/your/path/electrum455/README.md</code>, <code>sudo apt-get install libsecp256k1-dev</code> typical)</p>
</li>
<li><p>Clear the file <code>/your/path/electrum455/electrum/checkpoints.json</code> (<a href="https://github.com/spesmilo/electrum/issues/5469#issuecomment-506897704" rel="nofollow noreferrer">ensures all headers are downloaded</a>, can be left if only recent headers required)</p>
</li>
<li><p>Change directory to <code>/your/path/electrum</code></p>
</li>
<li><p>run Electrum using the command <code>./run_electrum</code> and go through wallet setup</p>
</li>
</ol>
<p>Electrum will now create a file called <code>blockchain_headers</code> in the <code>~/.electrum</code> directory.</p>
<p>Within a short time &lt;30 mins, the file will contain the binary block headers in order, that can be parsed.</p>

CC BY-SA 4.0
2024-06-24T10:02:36.820Z
2024-06-24T10:02:36.820Z
Lee
<p>I'd like to download all the blockheaders for the blockchain directly from the network (not an external API) ... what is the best way to do this?</p>
<p>I don't actually care about the transaction data and have no need for it, specifically, I need the difficulty level at each block, along with the timestamp. I know there are API's etc. to get this information but I specifically do not want to do that for my use case. I would not like to run the entire bitcoind service locally (there is too much overhead downloading the whole chain, verifying it etc.)</p>

<bitcoind><block-header><raw-data>
How to download just the blockheaders for the blockchain
user491880
# How to download just the blockheaders for the blockchain

(Asked by: username_0 on 2022-01-16)

I'd like to download all the blockheaders for the blockchain directly from the network (not an external API) ... what is the best way to do this?

I don't actually care about the transaction data and have no need for it, specifically, I need the difficulty level at each block, along with the timestamp. I know there are API's etc. to get this information but I specifically do not want to do that for my use case. I would not like to run the entire bitcoind service locally (there is too much overhead downloading the whole chain, verifying it etc.)

**Tags:** bitcoind, block-header, raw-data


---

## 2 answers

### Answer by username_1 on 2022-01-16. Score: 3

You can make it with [getheaders](https://en.bitcoin.it/wiki/Protocol_documentation#getheaders) p2p message, will return headers of blocks in a range.  
Remember of [handshaking](https://en.bitcoin.it/wiki/Protocol_documentation#version) and setting tx-relay to false.

> **Comments:**
> **username_0**: Thanks! This is what I'm looking for. Is there a C++ library that could handle sending/receiving the data?  

---

### Answer by username_2 on 2024-06-24. Score: 0

A procedure for doing this using [Electrum](https://electrum.org/) 4.5.5 on Ubuntu:

1. Download the Electrum Python code (from here; <https://electrum.org/#download>
   ) and save to `/your/path/electrum455`
2. Ensure you have the necessary dependencies (consult `/your/path/electrum455/README.md`, `sudo apt-get install libsecp256k1-dev` typical)
3. Clear the file `/your/path/electrum455/electrum/checkpoints.json` ([ensures all headers are downloaded](https://github.com/spesmilo/electrum/issues/5469#issuecomment-506897704), can be left if only recent headers required)
4. Change directory to `/your/path/electrum`
5. run Electrum using the command `./run_electrum` and go through wallet setup

Electrum will now create a file called `blockchain_headers` in the `~/.electrum` directory.

Within a short time <30 mins, the file will contain the binary block headers in order, that can be parsed.


---

