How get raw block data?

2

I can use getblock json rpc method to get parsed block, but I need raw data. Is there any way to get raw block data using bitcoin core?

Andrey Lobarev

Posted 2017-09-23T13:53:11.533

Reputation: 133

You can read it directly from the blk*.dat files...Nate Eldredge 2017-09-23T14:27:29.617

So to implement such method as getrawblock I need to create my own index with filename and offset for each block, right?Andrey Lobarev 2017-09-23T18:02:33.547

In principle you can use the existing leveldb database in the blocks/index directory to locate the block data within the blk*.dat file by its hash. See https://en.bitcoin.it/wiki/Bitcoin_Core_0.11_(ch_2):_Data_Storage or https://bitcoin.stackexchange.com/questions/28168/what-are-the-keys-used-in-the-blockchain-leveldb-ie-what-are-the-keyvalue-pair for the data format.

Nate Eldredge 2017-09-24T02:26:16.240

Answers

5

There's a boolean parameter to that RPC call that'll return it as a hex string representing the binary contents of the block.

If verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'

getblock 'hash' 0 should return what you want.

alcio

Posted 2017-09-23T13:53:11.533

Reputation: 1 164