@nomicfoundation/ethereumjs-util
Version:
A collection of utility functions for Ethereum
21 lines • 967 B
JavaScript
import { addHexPrefix, bigIntToHex } from './bytes.js';
import { isHexPrefixed } from './internal.js';
/**
* Parses the geth genesis state into Blockchain {@link GenesisState}
* @param json representing the `alloc` key in a Geth genesis file
*/
export function parseGethGenesisState(json) {
const state = {};
for (let address of Object.keys(json.alloc)) {
let { balance, code, storage, nonce } = json.alloc[address];
// create a map with lowercase for easy lookups
address = addHexPrefix(address.toLowerCase());
balance = isHexPrefixed(balance) ? balance : bigIntToHex(BigInt(balance));
code = code !== undefined ? addHexPrefix(code) : undefined;
storage = storage !== undefined ? Object.entries(storage) : undefined;
nonce = nonce !== undefined ? addHexPrefix(nonce) : undefined;
state[address] = [balance, code, storage, nonce];
}
return state;
}
//# sourceMappingURL=genesis.js.map