A block file (blk.dat) is not in human readable form. I wanted to know if there is a way to extract the data of it. For example converting it into text with readable block header, version number, last block, merkle root, time, target and all of the transactions that are included in that block. The same way bitcoin core translates it to JSON.
I did something just like that last summer using Python using github parser code to get me 95% where I wanted to go. I was parsing the earliest blocks to do some analysis on coinbase transactions so my code likely doesn't handle the latest blocks as is however. I parsed the entire block file in a matter of minutes (granted I was parsing early smaller ones!) and harvested the fields I was interested in to sqllite database for post processing.
The following reference was useful to understand the fields and how they were encoded.
https://developer.bitcoin.org/reference/block_chain.htmlI tried a number of parsers and code examples until I got one that worked for what I was doing. I think this one was one of the more useful ones because it was standalone and I could review and edit any of the code if I needed. I didn't want to trust a 'black box' running on my PC
https://github.com/ragestack/blockchain-parser/https://github.com/ragestack/blockchain-parser/blob/master/README.mdBlockchain parser
Author: Denis Leonov
466611@gmail.comSimple script for parsing blkXXXXX.dat files of Bitcoin blockchain database.
This script also compatible with most of altcoins, after making some tiny tricks.
The one realisation of blockchain parser that allows you to explore the main database as close as possible.
Don't worry to email me your questions or suggestions about this parser.
No dependencies, no third-parties modules or libs needed. Just install Python standart release and run.
Make sure you change the paths for blkXXXXX.dat files and for the parsing results to yours. The script works only with fully downloaded blockchain dat files (that are ~134Mb).
This script convert the full blockchain raw database that is stored in blkXXXXX.dat files to the simple txt view.
If this was helpfull for you, don't hesistate to make a donations!!!
Bitcoin (BTC): 1FvssyzXNnmgHbJg2DYwb7rkzTrtT8adcL