I know that i can use getheader 'hash' from bitcoin core, but i can't use it for all blocks, it's time consuming. Is there a site where i can find all bitcoin blockheader? Like a blockchain site but shows the blockheader?

Help is appreciated, thank you

  • Do you want the whole header in e.g. hex format, or do you want each field separated, e.g. version = xxx, prevHash = xxx, ...? – Jivan Pal Feb 12 at 13:36
  • Hex formatted if it's possible – Hamita Feb 12 at 16:15

You can take advantage of Blockchain.com's API (formerly Blockchain.info).

You can access BTC blocks based on their block height via a URL of the form https://blockchain.info/rawblock/<height+1>. We use <height+1> because 1 is used as the index of the genesis block, which is instead usually referred to as block 0, as it is defined to have a height of 0.

By default, this endpoint provides a JSON dump of the data in the block, but you can get the raw block data as a hexadecimal string instead by appending the query string ?format=hex. For example, https://blockchain.info/rawblock/2?format=hex will give you the data in the block after the genesis block (the block with height 1) as a hexadecimal string.

The block header is 80 bytes, or 160 nibbles (hexadecimal characters), so you can e.g. use curl to fetch the data, and then head to truncate it to just the header, and then save that hex string to a file:

curl 'https://blockchain.info/rawblock/2?format=hex' | head -c 160 > block-1.txt

You can use a simple Bash script to automate this for all blocks:



for ((i=0; i <= latest_block_height; i++)); do
    if ! [ -f "block-$i.txt" ]; then
        curl 'https://blockchain.info/rawblock/'"$(($i + 1))"'?format=hex' | head -c 160 > "block-$i.txt"
    echo "Downloaded block $i."
  • Thank you very much – Hamita Feb 12 at 17:11

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.