<p>You can take advantage of Blockchain.com's API (formerly Blockchain.info).</p>
<p>You can access BTC blocks based on their block height via a URL of the form <code>https://blockchain.info/rawblock/&lt;height+1&gt;</code>. We use <code>&lt;height+1&gt;</code> 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.</p>
<p>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 <code>?format=hex</code>. For example, <code>https://blockchain.info/rawblock/2?format=hex</code> will give you the data in the block after the genesis block (the block with height 1) as a hexadecimal string.</p>
<p>The block header is 80 bytes, or 160 nibbles (hexadecimal characters), so you can e.g. use <code>curl</code> to fetch the data, and then <code>head</code> to truncate it to just the header, and then save that hex string to a file:</p>
<pre><code>curl 'https://blockchain.info/rawblock/2?format=hex' | head -c 160 &gt; block-1.txt
</code></pre>
<p>You can use a simple Bash script to automate this for all blocks:</p>
<pre><code>#!/bin/bash

latest_block_height=670288

for ((i=0; i &lt;= latest_block_height; i++)); do
    if ! [ -f &quot;block-$i.txt&quot; ]; then
        curl 'https://blockchain.info/rawblock/'&quot;$(($i + 1))&quot;'?format=hex' | head -c 160 &gt; &quot;block-$i.txt&quot;
    fi
    echo &quot;Downloaded block $i.&quot;
done
</code></pre>

CC BY-SA 4.0
2021-02-12T16:43:47.867Z
2021-02-12T16:43:47.867Z
Jivan Pal
<p>I know that i can use <code>getheader 'hash'</code> 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?</p>
<p>Help is appreciated, thank you</p>

CC BY-SA 4.0
2021-02-12T13:36:04.670Z
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
CC BY-SA 4.0
2021-02-12T16:15:48.050Z
Hex formatted if it's possible
Hamita
CC BY-SA 4.0
2024-06-24T10:03:43.303Z
https://bitcoin.stackexchange.com/a/123438/34190
Lee
<block-header>
How to get the list of blockheader
Hamita
# How to get the list of blockheader

(Asked by: username_0 on 2021-02-04)

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

**Tags:** block-header

> **Comments:**
> **username_1**: Do you want the whole header in e.g. hex format, or do you want each field separated, e.g. `version = xxx, prevHash = xxx, ...`?  
> **username_0**: Hex formatted if it's possible  
> **username_2**: https://bitcoin.stackexchange.com/a/123438/34190  

---

## 1 answers

### Answer by username_1 on 2021-02-12. Score: 2 | Accepted answer

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/. We use  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:
#!/bin/bash

latest_block_height=670288

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"
    fi
    echo "Downloaded block $i."
done


---

