Author

Topic: Methods of decoding a bitcoin block stored in windows (Read 157 times)

full member
Activity: 161
Merit: 230
One important thing to note is that those .blk files do not necessarily contain the blocks in the correct order, as they are written to the files as they are received, and during bootstrapping and syncing, lots of blocks are coming all at once. The files also might contain orphaned blocks.
jr. member
Activity: 31
Merit: 12
Thanks for all your valuable insights. My ₿ journey gets more interesting everyday. A little late but I guess better late than never...
hero member
Activity: 882
Merit: 5834
not your keys, not your coins!
If you mean decoding the block and such, honestly the best tool is just using Bitcoin Core which you seem to have installed.
But if you want to decode individual blk files, I found this small program that might do the trick!

python-bitcoin-blockchain-parser]This repository actually looks a bit better to me, since it has more features and it's Python 3-based so you won't need to compile it!

Those script haven't updated in a while, so i have concern it can't parse taproot transaction/block correctly. Bitcoin Core is safer option unless OP willing to test those script and also offer to return raw hex of the block.

Code:
getblock [HASH_OF_THE_BLOCK] 0
Yes, true, makes sense; however it appeared to me that they're trying to do it semi-manually at least. For that purpose, the Python code is easier / more accessible to copy out parts of it into own scripts or play around with them without recompilation of a big software like Bitcoin Core. Of course Core can decode any block ('honestly the best tool is just using Bitcoin Core'); but since he mentioned trying to just decode the genesis block, the old scripts should work.
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
Secondly the blocks are not 1MB they are like 127MB.
How do block explorer or a normal person decode this information from these blocks?
Thanks in advance.

I'd like to mention Bitcoin protocol doesn't specify how you store blockchain on your device. If you use different full node software (Bitcoin Core isn't the only one), it's possible they store blockchain differently.

If you mean decoding the block and such, honestly the best tool is just using Bitcoin Core which you seem to have installed.
But if you want to decode individual blk files, I found this small program that might do the trick!

python-bitcoin-blockchain-parser]This repository actually looks a bit better to me, since it has more features and it's Python 3-based so you won't need to compile it!

Those script haven't updated in a while, so i have concern it can't parse taproot transaction/block correctly. Bitcoin Core is safer option unless OP willing to test those script and also offer to return raw hex of the block.

Code:
getblock [HASH_OF_THE_BLOCK] 0
hero member
Activity: 882
Merit: 5834
not your keys, not your coins!
Hello everyone,
Started doing some research on bitcoin blocks, when i run a node the blocks are stored on  => ...\BTC\blocks (windows)
I opened with hex viewer and I could indeed see the infamous"chancelor..." in the genesis block.
How can the transaction history be decoded from this block.
You need all blocks to get full transaction history. Wink
If you mean decoding the block and such, honestly the best tool is just using Bitcoin Core which you seem to have installed.
But if you want to decode individual blk files, I found this small program that might do the trick!

python-bitcoin-blockchain-parser]This repository actually looks a bit better to me, since it has more features and it's Python 3-based so you won't need to compile it!

For doing it manually, I like to follow along code such as the one from the link above. As you can see, there is this hex code that you should be able to find in your .dat file, which separates blocks. If you count the bytes between these separators, it should be always around 1MB.
Code: (https://github.com/alecalve/python-bitcoin-blockchain-parser/blob/d763ca6dc2357cdf2e885f3e6790eeab1aeaa0a8/blockchain_parser/blockchain.py#L30)
BITCOIN_CONSTANT = b"\xf9\xbe\xb4\xd9"

In line 46, in get_blocks(), you can see how one blk....dat file is split up and the raw bytes of each block are returned.

For decoding that block manually, you can have a look into the codebase of the above project or refer to the Block structure according to Bitcoin Wiki.
Here's the block header and the corresponding Bitcoin Core code is found here.
Code: (https://github.com/bitcoin/bitcoin/blob/2f0f056e08cd5a1435120592a9ecd212fcdb915b/src/primitives/block.h#L20)
// header
int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
uint32_t nTime;
uint32_t nBits;
uint32_t nNonce;

Secondly the blocks are not 1MB they are like 127MB.
How do block explorer or a normal person decode this information from these blocks?
Thanks in advance.
That's because one such file contains more than one block.
jr. member
Activity: 31
Merit: 12
Hello everyone,
Started doing some research on bitcoin blocks, when i run a node the blocks are stored on  => ...\BTC\blocks (windows)
I opened with hex viewer and I could indeed see the infamous"chancelor..." in the genesis block.
How can the transaction history be decoded from this block.

Secondly the blocks are not 1MB they are like 127MB.
How do block explorer or a normal person decode this information from these blocks?
Thanks in advance.
Jump to: