2

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.)

2 Answers 2

3

You can make it with getheaders p2p message, will return headers of blocks in a range.
Remember of handshaking and setting tx-relay to false.

1
  • Thanks! This is what I'm looking for. Is there a C++ library that could handle sending/receiving the data?
    – user491880
    Commented Jan 16, 2022 at 23:47
0

A procedure for doing this using Electrum 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, 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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