<p>I see two broad solutions:</p>
<h3>Use an API that allows you to get blocks by block height</h3>
<p>BlockChain.info allows you to query for blocks at a certain height. Example:</p>
<pre><code>https://blockchain.info/block-height/100?format=json
</code></pre>
<p>returns</p>
<pre><code>{ &quot;blocks&quot; : [
{
    &quot;hash&quot;:&quot;000000007bc154e0fa7ea32218a72fe2c1bb9f86cf8c9ebf9a715ed27fdb229a&quot;,
    &quot;ver&quot;:1,
(snipped)
</code></pre>
<p>(Remember to filter out blocks that aren't on the main chain, by looking at the &quot;main_chain&quot; attribute.)</p>
<p>You can take that hash, and look up the block:</p>
<pre><code>https://blockchain.info/rawblock/000000007bc154e0fa7ea32218a72fe2c1bb9f86cf8c9ebf9a715ed27fdb229a
</code></pre>
<p>returns</p>
<pre><code>{
    &quot;hash&quot;:&quot;000000007bc154e0fa7ea32218a72fe2c1bb9f86cf8c9ebf9a715ed27fdb229a&quot;,
    &quot;ver&quot;:1,    
    &quot;prev_block&quot;:&quot;00000000cd9b12643e6854cb25939b39cd7a1ad0af31a9bd8b2efe67854b1995&quot;,
    &quot;mrkl_root&quot;:&quot;2d05f0c9c3e1c226e63b5fac240137687544cf631cd616fd34fd188fc9020866&quot;,
    &quot;time&quot;:1231660825,
(snipped)
</code></pre>
<p>(This is in a JSON format custom to BlockChain - I haven't found any API providers that will return the raw block. Kinda annoying.)</p>
<h3>Write a client that gets the blocks from the network</h3>
<p>This downloads the headers of the Bitcoin blockchain (much smaller than the whole blockchain). Then, it goes through the block headers and downloads the ones you want.</p>
<pre><code>WalletAppKit kit = new WalletAppKit(MainNetParams.get(), new java.io.File(&quot;.&quot;), &quot;test&quot;);
// Download headers
kit.startAndWait();
BlockChain chain = kit.chain();
BlockStore bs = chain.getBlockStore();
Peer peer = kit.peerGroup().getDownloadPeer();
// Get last block
StoredBlock current = bs.getChainHead();
// Loop until you reach the genesis block
while(current.getHeight() &gt; 1) {
    // Fully download blocks between 100 and 200
    if(100 &lt;= current.getHeight() &amp;&amp; current.getHeight() &lt;= 200) {
        Block b = peer.getBlock(current.getHeader().getHash()).get();
        System.out.println(b);
    }
    current = current.getPrev(bs);
}
</code></pre>
<p>This example uses BitcoinJ, but other SPV Bitcoin libraries can do this too.</p>
<p><a href="https://bitcoin.stackexchange.com/a/22242">(Thanks to Diego Basch for the code.)</a></p>

CC BY-SA 3.0
2015-01-08T01:02:15.193Z
2015-01-08T15:23:01.597Z
2020-06-16T11:10:03.350Z
Nick ODell
<p>I want to download blk.dat of a specific block number, How can I do this ?</p>

<p>Note: I'm only interested in specific blocks, I only want to download blocks for example that are numbered between 100 and 200,etc...</p>

CC BY-SA 3.0
2015-01-07T02:43:12.103Z
Your question title and question text seem to be asking two different questions. Are you interested in getting a raw block by index, or a group of blocks in blkindex format, or something else?
Nick ODell
CC BY-SA 3.0
2015-01-07T11:13:04.243Z
@NickODell I want group of blocks, but this group of blocks should contain blocks that I specify, for example between 120000 and 130000,
ka lin
CC BY-SA 3.0
2015-01-07T12:37:12.940Z
Maybe if you read this [mastering bitcoin - chapter 7](http://chimera.labs.oreilly.com/books/1234000001802/ch07.html) you will get your answaer. It's not much to read :)
Sebastian Xawery Wiśniowiecki
CC BY-SA 3.0
2015-01-07T12:38:27.513Z
Block are unnumbered, they are more like linked list.
Sebastian Xawery Wiśniowiecki
CC BY-SA 3.0
2015-01-07T12:48:29.083Z
@XaweryWiśniowiecki I know that I can get block information using the block hash in bitcoin client, I can use getblock "hash", but this function require the blocks to be already in the hard drive, so without downloading the whole blockchain, how can I download only specific blocks  ?
ka lin
<blockchain><bootstrap.dat>
How to download blk.dat files from a specific block number?
ka lin
# How to download blk.dat files from a specific block number?

(Asked by: username_0 on 2015-01-06)

I want to download blk.dat of a specific block number, How can I do this ?

Note: I'm only interested in specific blocks, I only want to download blocks for example that are numbered between 100 and 200,etc...

**Tags:** blockchain, bootstrap.dat

> **Comments:**
> **username_1**: Your question title and question text seem to be asking two different questions. Are you interested in getting a raw block by index, or a group of blocks in blkindex format, or something else?  
> **username_0**: @NickODell I want group of blocks, but this group of blocks should contain blocks that I specify, for example between 120000 and 130000,  
> **username_2**: Maybe if you read this [mastering bitcoin - chapter 7](http://chimera.labs.oreilly.com/books/1234000001802/ch07.html) you will get your answaer. It's not much to read :)  
> **username_2**: Block are unnumbered, they are more like linked list.  
> **username_0**: @XaweryWiśniowiecki I know that I can get block information using the block hash in bitcoin client, I can use getblock "hash", but this function require the blocks to be already in the hard drive, so without downloading the whole blockchain, how can I download only specific blocks  ?  

---

## 1 answers

### Answer by username_1 on 2015-01-08. Score: 3 | Accepted answer

I see two broad solutions:
Use an API that allows you to get blocks by block height
BlockChain.info allows you to query for blocks at a certain height. Example:
https://blockchain.info/block-height/100?format=json

returns
{ "blocks" : [
{
    "hash":"000000007bc154e0fa7ea32218a72fe2c1bb9f86cf8c9ebf9a715ed27fdb229a",
    "ver":1,
(snipped)

(Remember to filter out blocks that aren't on the main chain, by looking at the "main_chain" attribute.)
You can take that hash, and look up the block:
https://blockchain.info/rawblock/000000007bc154e0fa7ea32218a72fe2c1bb9f86cf8c9ebf9a715ed27fdb229a

returns
{
    "hash":"000000007bc154e0fa7ea32218a72fe2c1bb9f86cf8c9ebf9a715ed27fdb229a",
    "ver":1,    
    "prev_block":"00000000cd9b12643e6854cb25939b39cd7a1ad0af31a9bd8b2efe67854b1995",
    "mrkl_root":"2d05f0c9c3e1c226e63b5fac240137687544cf631cd616fd34fd188fc9020866",
    "time":1231660825,
(snipped)

(This is in a JSON format custom to BlockChain - I haven't found any API providers that will return the raw block. Kinda annoying.)
Write a client that gets the blocks from the network
This downloads the headers of the Bitcoin blockchain (much smaller than the whole blockchain). Then, it goes through the block headers and downloads the ones you want.
WalletAppKit kit = new WalletAppKit(MainNetParams.get(), new java.io.File("."), "test");
// Download headers
kit.startAndWait();
BlockChain chain = kit.chain();
BlockStore bs = chain.getBlockStore();
Peer peer = kit.peerGroup().getDownloadPeer();
// Get last block
StoredBlock current = bs.getChainHead();
// Loop until you reach the genesis block
while(current.getHeight() > 1) {
    // Fully download blocks between 100 and 200
    if(100 <= current.getHeight() && current.getHeight() <= 200) {
        Block b = peer.getBlock(current.getHeader().getHash()).get();
        System.out.println(b);
    }
    current = current.getPrev(bs);
}

This example uses BitcoinJ, but other SPV Bitcoin libraries can do this too.
(Thanks to Diego Basch for the code.)


---

