I am trying to download a block(Height:474044) using an API from here in python. Block is obviously downloaded in JSON format. But when I store it in a file on my system it shows very weird size number, not matching with actual blocksize on network. I also tried to download data in hex format using this link. But still, when I try to store it in a file(JSON/Text), It is not showing the size same as shown in block details officially. I have intentionally chosen a block before segwit BIP to avoid any further confusion. Help me to confirm my downloaded blocksize with actually mentioned on network. This question might seem naive to some users as I am new to bitcoin. Thanks for help in advance.
1 Answer
For one, there is no JSON block format - different APIs have different ways of interpreting and displaying a block in a JSON response, and none of them will ever match the block size.
Your mistake appears to be saving the actual hex block as text.
1996396 = 2 * 998198
You must write the data as an actual binary file. i.e., write 12
as the byte 0x12
, instead of saving the text "12" directly, which will write the bytes 0x3132
to disk, doubling the size of the file saved. Saving it as text will double the file size, as you've noticed already.