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

  • 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
    Commented Jan 7, 2015 at 2:43
  • @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
    Commented Jan 7, 2015 at 11:13
  • Maybe if you read this mastering bitcoin - chapter 7 you will get your answaer. It's not much to read :) Commented Jan 7, 2015 at 12:37
  • Block are unnumbered, they are more like linked list. Commented Jan 7, 2015 at 12:38
  • @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
    Commented Jan 7, 2015 at 12:48

1 Answer 1


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:



{ "blocks" : [

(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:




(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
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();
    current = current.getPrev(bs);

This example uses BitcoinJ, but other SPV Bitcoin libraries can do this too.

(Thanks to Diego Basch for the code.)

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.