Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
genesis balance formats

1. exporting fresh genesis.json for mainnet and ropsten with balances in hex

This PR adds dumpgenesis capability to geth: https://github.com/ethereum/go-ethereum/pull/20191

git clone git@github.com:etclabscore/ethereum.go-ethereum.git etc-geth
cd etc-geth
git checkout etclabscore:feat/cmd-dumpgenesis
make geth

./build/geth dumpgenesis > genesis-mainnet.json
./build/geth --testnet dumpgenesis > genesis-ropsten.json

2. Transforming genesis that came from geth

I'm using jq, a sed-like text manipulation for JSON.

  • Transform {… alloc:{address: {balance: 123}, …} to {address: 123}
  • Prepend 0x to address
  • geth dumpgenesis already comes with hex balances, so no balance transformation needed
cat genesis-mainnet.json | jq '.alloc | to_entries[] | { ("0x"+.key): .value.balance }' | jq -s add > mainnet.json

3. grabbing genesis from kovan, transforming it to our desired format

wget https://github.com/paritytech/parity-ethereum/blob/master/ethcore/res/ethereum/kovan.json

Transforms it to our genesis format, removing null entries

cat kovan.json | jq '.accounts | to_entries[] | {(.key): .value.balance}' | jq -s add | grep -v "null" > genesis-kovan.json

Manually converting the only decimal value to hex

echo "obase=16; 1606938044258990275541962092341162602522202993782792835301376" | bc

4. testing

  1. run npm run dist (ethereumjs-common)
  2. link/import this branch to ethereumjs-vm/node_modules/ethereumjs-common
  3. from ethereumjs-vm dir, run npm run build:dist && tape './tests/api/state/stateManager.js'

This test ensures genesis block hash matches state root for each chain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.