Skip to content

A CLI to help to check information in Ethereum state database

Notifications You must be signed in to change notification settings

shenghu/ethstatedb

Repository files navigation

ethstatedb

Command to check Ethereum state database

Version Downloads/week License CircleCI Coverage Status semantic-release

This cli is created when I was studying Ethereum. I was curious about when and how an accout is created and maintained by Ethereum state database. From Diving into Ethereum's world state, it explains that accounts are not created in state database until there is a transaction for it. So I create this small tool to verify it.

Usage

$ npm install -g ethstatedb

$ ethstatedb account -d .db/chaindata/ -r 0xecc60e00b3fe5ce9f6e1a10e5469764daf51f1fe93c22ec3f9a7583a80357217 0x095e7baea6a6c7c4c2dfeb977efac326af552

Address   0x095e7baea6a6c7c4c2dfeb977efac326af552 
Balance   0                                       
Nonce     0                                       
StateRoot                                         
CodeHash 

Commands

ethstatedb account [ADDRESS]

Retrieve account information from Ethereum state database

USAGE
  $ ethstatedb account ADDRESS

ARGUMENTS
  ADDRESS  public key of an account, e.g. 
           0x7C476EA4e20D6d49820Ee810C0C474ED11b3f527

OPTIONS
  -d, --dbdir=dbdir    (required) path of Ethereum state database, e.g. 
                       ethereum/geth/chaindata

  -h, --help           show CLI help

  -r, --root=root      (required) value of stateRoot

  --skip-copy          skip copying database to .ethstatedb. By default, 
                       database is copied to avoid messing the original 
                       database.

  --work-dir=work-dir  directory to pull down database

EXAMPLE
  $ ethstatedb account --dbdir /home/data/ethereum-node1/geth/chaindata --root 
  0x595e3a0db7f38600770a267b12b67a8da1c202fef4b6c21e60fdb92477d89753 
  0x7C476EA4e20D6d49820Ee810C0C474ED11b3f527

ethstatedb help

Display help for ethstatedb

Command to check Ethereum state database

VERSION
  ethstatedb/1.0.5 darwin-x64 node-v10.15.3

USAGE
  $ ethstatedb [COMMAND]

COMMANDS
  account  load information of an account
  help     display help for ethstatedb

More information

  1. When playing with data generated by geth, make sure to stop geth so that it flushes all data to database. This command by default copies the data to a temp location, i.e. .ethstatedb, to avoid messing up the original database. However, you can use --skip-copy to use original database.
  2. To get stateRoot, use geth attach ipc://path/to/geth.ipc to connect to a node. Then use eth.getBlock(eth.blockNumber).stateRoot to get stateRoot for the latest block. You can change eth.blockNumber to be number of the specific block that you are interested in.

References

  1. ethereum_database_research_and_testing
  2. ethereumjs-vm
  3. Diving into Ethereum's world state