Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: d5000 on April 24, 2016, 09:53:18 AM



Title: Is it possible to download a block manually?
Post by: d5000 on April 24, 2016, 09:53:18 AM
I am curious if there is a method to download a single block from the blockchain manually.

With "manually" I mean to download it with, for example, Linux shell commands, or a simple Python script.

I'm not expecting a tutorial obviously, as this surely is a bit "strange" question. I am no Bitcoin expert nor really a coder (so I cannot dive into the code and extract the needed information) , but I understand a bit of technical documentation, so if there is documentation for (at least some of) the needed steps probably a link to it will be all I need. It is mainly because I want to understand the system a bit better.

(I have already googled this topic and found only this (https://en.bitcoin.it/wiki/Block_chain_download), but it's a bit rudimentary).


Title: Re: Is it possible to download a block manually?
Post by: amaclin on April 24, 2016, 11:11:22 AM
With "manually" I mean to download it with, for example, Linux shell commands, or a simple Python script.

curl https://webbtc.com/block/000000000000000003d687c4f4e88b7ab642991fc9c2174aa1401477c3b865f9.bin


Title: Re: Is it possible to download a block manually?
Post by: d5000 on April 24, 2016, 01:14:12 PM
With "manually" I mean to download it with, for example, Linux shell commands, or a simple Python script.

curl https://webbtc.com/block/000000000000000003d687c4f4e88b7ab642991fc9c2174aa1401477c3b865f9.bin

Using a blockchain explorer is a possibility I didn't consider.

I forgot to mention that in fact, I would like to download the block from the real Bitcoin network, that means to connect to another client and download it from there. I'm more interested in the process than in the result.

Thanks anyway!


Title: Re: Is it possible to download a block manually?
Post by: achow101 on April 24, 2016, 02:46:46 PM
I forgot to mention that in fact, I would like to download the block from the real Bitcoin network, that means to connect to another client and download it from there. I'm more interested in the process than in the result.
You would need to have a program that can send all of the Bitcoin network messages. You would first need to go through the handshake process and then request whatever block you want from another node. There is more info on the network messages here: https://bitcoin.org/en/developer-reference#p2p-network.

First, to start the handshake, you need to connect to another node and send them a version message. Then that node will respond with a verack message and a version. You must respond to the version with a verack. If you want to keep the connection alive, you need to be able to handle ping and pong messages as well. Then you can request blocks using the getblocks message and the getdata message to download the blocks.


Title: Re: Is it possible to download a block manually?
Post by: amaclin on April 24, 2016, 04:15:00 PM
I'm more interested in the process than in the result.
Have a look
https://github.com/sebicas/bitcoin-sniffer


Title: Re: Is it possible to download a block manually?
Post by: d5000 on April 25, 2016, 03:35:50 AM
Thanks knightdk and amaclin! Both answers are of great help to me.

I will dive a bit into the article about messages and look at the Bitcoin sniffer code too, so I get an idea about the process to download the blocks and if it's feasible for me to write such a simple "block-downloader-script".