Hey everyone, I’m totally new to coding and I’m looking to grab the latest raw block in hex format as a text file.
Any ideas on how to do this?
I’ve tried using Blockchain explorers, but they don’t provide the raw files. I really need to get my hands on it.
How to easily obtain the raw Block file?
12 replies 130 views
You can get raw data for each of the blocks from blockchair.com.
For example, the following link gives you the raw data for block number 920744.
Replace the block hash with the hash of any other block to get its raw data.
Getting the raw hex block file without any coding experience is not something you can do by clicking around a standard web-based block explorer. But, like hosemary mentioned, you could try a public blockchain API. It still means making a request, but you don't have to write code a web browser or a simple tool like curl can do the job. Many popular explorers, such as Blockchair.com or BlockCypher, have free APIs just for this. First, find the latest block hash or height. The main explorer site can help, or you can get info via an API call.
Like this:
Then, find the "best_block_hash" value and paste that into the URL from the example before. Or, find the "best_block_height" value and use that instead. This will give you the raw data for the latest block on the bitcoin chain.
^^^
Adding a tip: to get the latest block hash, use this url:
Then combine it with the blockchair API endpoint above.
gr3g.0rbitHero Member
Posts: 1025 · Reputation: 2646
#5Jul 19, 2017, 03:11 PM
Some blockexplorer API do, but its free version comes with a limit.
Do you have a fully synced Bitcoin node?
If so, just use getbestblockhash then use getblock "bestblockhash" 0 use verbose "0" like so.
e.g. (Bitcoin Core Console):
e.g. (bitcoin-cli):
Thanks a lot for the helpful answers, I was able to see the raw Block on my Safari explorer, Brave refused to show it.
And damn, its just a huge wall of text lol.
I was expecting something more elegant, like the famous Genesis Block.
But Im glad I got it.
Also I do plan to become a node in the near future and film the entire process of downloading the Blockchain, but not right now.
Im glad I can get the help I need here ^^
The genesis block included only 1 transaction and that's why it was much smaller.
It may be worth mentioning that you can also get the raw data for transactions separately, so that you deal with smaller data.
This gives you the raw data for a single transaction. Just replace the transaction hash with the hash of any other transaction to get its raw data.
To get the raw data of transactions, you can also go to mempool.space and click "Transaction hex" under the transaction details.
gr3g.0rbitHero Member
Posts: 1025 · Reputation: 2646
#8Jul 19, 2017, 10:05 PM
Do they still have a working blockexplorer service?
Because it doesn't work at my end, the URL itself, and either replacing "block" with the block hash/height or appending it to the given URL.
It always says "403 - Forbidden" whether I use Tor or any clearnet browser.
That doesn't look like a block explorer at all. Going to the home page, it is just hosting the bitcoin paper with 2 links on top one leading to a shady thing that slows down the browser and looks like it is selling some cloud mining service!
gr3g.0rbitHero Member
Posts: 1025 · Reputation: 2646
#10Jul 20, 2017, 07:59 AM
AFAIK, it had a blockexplorer service before alongside with their wallet.
That's why I'm wondering why Furball808 suggested it now that it's not what it used to be.
Perhaps it's just a simple "haven't tested an old bookmark" before posting or something else.
The majority of the blockchain internet explorer services do not display the complete raw block files in hex format as it is standard practice. You can still obtain this information if you are in control of your own copy of the Bitcoin Core and utilize the getblock RPC method with verbosity setting to zero (0) to receive the complete raw hex block information.
All that is necessary to do this is to download and install Bitcoin Core, allow time to sync, and execute the getblock RPC method with verbosity setting 0. If you want to receive the latest raw block data from the blockchain, you must be running a Bitcoin Core as this is the only way to receive accurate raw block data from the blockchain.
That's a lot of work to just get a couple of blocks though. Here's a cool but slightly harder method: write a small script that connects to other peers on the bitcoin P2P network aka nodes, and request the block you need using a getdata message and the block's hash
You can start by reading this to get the idea: https://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html
The process is pretty much the same.
- Find peers, connect to one
- Send/receive version and verack messages to complete the handshake process
- Instead of last step of the above article (which is sending a tx message) you need to send a getdata message with an inv message that has MSG_WITNESS_BLOCK (2 | (1 << 30)) as its type.
I think it's easier to use mempool.space's GET Block Raw endpoint. This gives you the raw block data and if you want that as a continuous hex string, xxd is there for you.
On the command-line you can execute e.g. the following pipeline which gives you the Genesis block in hex:
To obtain the block hash from a numerical block-height, see the following description of a suitable existing endpoint: https://mempool.space/docs/api/rest#get-block-height
Related topics
- Bitcoin Core displaying coins (UTXOs) in a new tab 13
- Are you in favor of BIP-110? Let's get a Bitcoin poll going. 0
- Erlay seems to have some issues here’s a better proposal for a bitcoin protocol without invites 3
- New Optional Hourglass Implementation is Live 3
- Ways to earn some sats by contributing to bitcoin core development 5
- Exploring the Potential and Challenges of a Kardashev-Scale Bitcoin Network 3