Blockchain By Example
上QQ阅读APP看书,第一时间看更新

Using the local blockchain

If Bitcoin Core has finished syncing the blockchain, you can locally parse the blocks to locate our transaction and read the stored message.

To open and parse the blockchain blocks, we need to install a graphical hex editor such as bless, by running sudo apt-get install bless.

Once installed, you can run it and open one of the .blk files present in the blocks directory:

As shown in the screenshot, bless will display a pane divided into three parts:

  • The left column is the offset column
  • The center column displays the blocks' hexadecimal content
  • The right column is the same line of data as in the center, with recognized text characters displayed as text and binary values represented by period characters

To locate our transaction, you can search for it by pasting the unsigned raw transaction string into the Search field. You may go through a few blk**.dat files before you find your transaction. In my case, I found it in the blk00100.dat file. 

At first glance, it may not be very meaningful, but once you locate your transaction you can easily locate the message you’ve stored in the blockchain. The hello world message will be visible in the ASCII section on the right.

You can also locate the block that encompasses the transaction by searching for the previous block delimiter, called magic bytes, represented by 0b110907. Then you can, by following the structure of the block, determine the meaning of these long hexadecimal strings.

In the previous screenshot, I delimited the block with a yellow border and highlighted the blocks header field with multiple colors. I delimited our transaction and the coinbase transaction in blue and gray, respectively.

As you'll be running in prune mode, you will not be able to see my transaction, as you will have only synced newer blocks. However, you'll be able to see your transaction by following the same process.

To help you visualize the block content, the following table explains the meaning of the previously highlighted bytes:

And that's it! You can now send transactions with extra messages into the blockchain, and retrieve the data online or locally. Although this is not usually required, it may prove useful in the future. 

Let's go ahead and send another raw transaction with an OP_RETURN output using a different method.