3

I want to get ethereum blocks as binary data and parse them manually to get raw ethereum transactions. Are there any good manuals how to do it?

UPDATE: how ethereum genesis block (at height #0) looks like in binary (hex) form?

amaclin
  • 131
  • 4
  • Does this help? https://ethereum.stackexchange.com/questions/1474/how-can-you-parse-blockchain-files-stored-in-a-local-node-to-get-blocks-and-tran?rq=1 – Richard Horrocks Apr 09 '17 at 16:55
  • 1
    I do not see a simple way to get a block as raw data. In bitcoin I can get any block for example the genesis useful links: [hex] [binary]. I am looking for raw data, not for json or any other – amaclin Apr 09 '17 at 17:10
  • The raw data is stored as a levelDB database. If you want to read the data directly from the .ldb files you'd need to write a tool that understood the database's schema, and was able to decode the RLP encodings . (I can't remember if something like that already exists - I can't immediately see anything.) If you want to roll your own, I could point you to the Go code in Geth that creates the files? – Richard Horrocks Apr 09 '17 at 19:11
  • 1
    I already started to write my own lib/tool to decode RLP in cpp :) I have some experience to parse bitcoin ldb-files. – amaclin Apr 09 '17 at 19:17
  • 2
    Brilliant - good luck! :) – Richard Horrocks Apr 09 '17 at 19:19
  • EthSlurp, which is part of QuickBlocks.io, can do this easily in C++. It's available on GitHub. – Thomas Jay Rush Apr 24 '17 at 05:25

1 Answers1

2

Run the following commands (with Geth 1.10.18-stable):


rm -fR /tmp/foo; geth --syncmode full --datadir /tmp/foo
...
... Imported new chain segment               blocks=2

Press Ctrl-C when there are some blocks being downloaded.


rm /tmp/block0; geth --datadir /tmp/foo export /tmp/block0 0 0

ls -l /tmp/block0

The size of the file should be 540 bytes.


% hexdump -C /tmp/block0
00000000  f9 02 19 f9 02 14 a0 00  00 00 00 00 00 00 00 00  |................|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 a0  1d cc 4d e8 de c7 5d 7a  |..........M...]z|
00000030  ab 85 b5 67 b6 cc d4 1a  d3 12 45 1b 94 8a 74 13  |...g......E...t.|
00000040  f0 a1 42 fd 40 d4 93 47  94 00 00 00 00 00 00 00  |..B.@..G........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 a0 d7 f8  |................|
00000060  97 4f b5 ac 78 d9 ac 09  9b 9a d5 01 8b ed c2 ce  |.O..x...........|
00000070  0a 72 da d1 82 7a 17 09  da 30 58 0f 05 44 a0 56  |.r...z...0X..D.V|
00000080  e8 1f 17 1b cc 55 a6 ff  83 45 e6 92 c0 f8 6e 5b  |.....U...E....n[|
00000090  48 e0 1b 99 6c ad c0 01  62 2f b5 e3 63 b4 21 a0  |H...l...b/..c.!.|
000000a0  56 e8 1f 17 1b cc 55 a6  ff 83 45 e6 92 c0 f8 6e  |V.....U...E....n|
000000b0  5b 48 e0 1b 99 6c ad c0  01 62 2f b5 e3 63 b4 21  |[H...l...b/..c.!|
000000c0  b9 01 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001c0  00 00 00 85 04 00 00 00  00 80 82 13 88 80 80 a0  |................|
000001d0  11 bb e8 db 4e 34 7b 4e  8c 93 7c 1c 83 70 e4 b5  |....N4{N..|..p..|
000001e0  ed 33 ad b3 db 69 cb db  7a 38 e1 e5 0b 1b 82 fa  |.3...i..z8......|
000001f0  a0 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000210  00 88 00 00 00 00 00 00  00 42 c0 c0              |.........B..|
0000021c
LCamel
  • 61
  • 3