Genesis Configuration

Introduction

Functionalities and entities to obtain the genesis configurations for different chains.

Module Contents

Classes

GenesisConfiguration

Configuration for the first block of an Ethereum chain.

Functions

genesis_configuration

Obtain the genesis configuration from the given genesis json file.

Module Details

GenesisConfiguration

Configuration for the first block of an Ethereum chain.

Specifies the allocation of ether set out in the pre-sale, and some of the fields of the genesis block.

class GenesisConfiguration
chain_id :ethereum.base_types.Uint64
difficulty :ethereum.base_types.Uint
extra_data :ethereum.base_types.Bytes
gas_limit :ethereum.base_types.Uint
nonce :ethereum.base_types.Bytes8
timestamp :ethereum.base_types.U256
initial_balances :Dict[ethereum.frontier.eth_types.Address, ethereum.base_types.U256]

genesis_configuration

genesis_configuration(genesis_file)

Obtain the genesis configuration from the given genesis json file.

The genesis file should be present in the assets directory.

Parameters

genesis_file – The json file which contains the parameters for the genesis block and the pre-sale allocation data.

Returns

configuration – The genesis configuration obtained from the json genesis file.

Return type

GenesisConfiguration

def genesis_configuration(genesis_file: str) -> GenesisConfiguration:
    genesis_str_data = cast(
        bytes, pkgutil.get_data("ethereum", f"assets/{genesis_file}")
    ).decode()
    genesis_data = json.loads(genesis_str_data)

    initial_balances = {
        hex_to_address(address): hex_to_u256(account["balance"])
        for address, account in genesis_data["alloc"].items()
    }

    return GenesisConfiguration(
        chain_id=Uint64(genesis_data["config"]["chainId"]),
        difficulty=hex_to_uint(genesis_data["difficulty"]),
        extra_data=hex_to_bytes(genesis_data["extraData"]),
        gas_limit=hex_to_uint(genesis_data["gasLimit"]),
        nonce=hex_to_bytes8(genesis_data["nonce"]),
        timestamp=hex_to_u256(genesis_data["timestamp"]),
        initial_balances=initial_balances,
    )