Skip to main content

Common

Common class to access chain and hardfork parameters and to provide a unified and shared view on the network and hardfork state.

Use the Common.custom static constructor for creating simple custom chain Common objects (more complete custom chain setups can be created via the main constructor and the CommonOpts.customChains parameter).

Hierarchy

Index

Constructors

publicconstructor

Properties

publicreadonlyDEFAULT_HARDFORK

DEFAULT_HARDFORK: string

Methods

public_calcForkHash

  • _calcForkHash(hardfork: string, genesisHash: Uint8Array): string
  • Internal helper function to calculate a fork hash


    Parameters

    • hardfork: string

      Hardfork name

    • genesisHash: Uint8Array

      Genesis block hash of the chain

    Returns string

    Fork hash as hex string

public_getHardfork

  • Internal helper function, returns the params for the given hardfork for the chain set


    Parameters

    • hardfork: string

      Hardfork name

    Returns null | HardforkConfig

    Dictionary with hardfork params or null if hardfork not on chain

publicactiveOnBlock

  • activeOnBlock(blockNumber: Numbers): boolean
  • Alias to hardforkIsActiveOnBlock when hardfork is set


    Parameters

    Returns boolean

    True if HF is active on block number

publicbootstrapNodes

  • Returns bootstrap nodes for the current chain


    Returns undefined | BootstrapNodeConfig[]

    Dict with bootstrap nodes

publicchainId

  • chainId(): bigint
  • Returns the Id of current chain


    Returns bigint

    chain Id

publicchainName

  • chainName(): string
  • Returns the name of current chain


    Returns string

    chain name (lower case)

publicconsensusAlgorithm

  • consensusAlgorithm(): string
  • Returns the concrete consensus implementation algorithm or protocol for the network e.g. "ethash" for "pow" consensus type, "clique" for "poa" consensus type or "casper" for "pos" consensus type.

    Note: This value can update along a Hardfork.


    Returns string

publicconsensusConfig

  • consensusConfig(): {}
  • Returns a dictionary with consensus configuration parameters based on the consensus algorithm

    Expected returns (parameters must be present in the respective chain json files):

    ethash: empty object clique: period, epoch casper: empty object

    Note: This value can update along a Hardfork.


    Returns {}

publicconsensusType

  • consensusType(): string
  • Returns the consensus type of the network Possible values: "pow"|"poa"|"pos"

    Note: This value can update along a Hardfork.


    Returns string

publiccopy

  • Returns a deep copy of this Common instance.


    Returns Common

publicdnsNetworks

  • dnsNetworks(): string[]
  • Returns DNS networks for the current chain


    Returns string[]

    Array of DNS ENR urls

publiceipBlock

  • eipBlock(eip: number): null | bigint
  • Returns the hardfork change block for eip


    Parameters

    • eip: number

      EIP number

    Returns null | bigint

    Block number or null if unscheduled

publiceips

  • eips(): number[]
  • Returns the active EIPs


    Returns number[]

    List of EIPs

publicforkHash

  • forkHash(_hardfork?: string, genesisHash?: Uint8Array): string
  • Returns an eth/64 compliant fork hash (EIP-2124)


    Parameters

    • optional_hardfork: string
    • optionalgenesisHash: Uint8Array

      Genesis block hash of the chain, optional if already defined and not needed to be calculated

    Returns string

publicgenesis

  • Returns the Genesis parameters of the current chain


    Returns GenesisBlockConfig

    Genesis dictionary

publicgetHardforkByBlockNumber

  • Returns the hardfork based on the block number or an optional total difficulty (Merge HF) provided.

    An optional TD takes precedence in case the corresponding HF block is set to null or otherwise needs to match (if not an error will be thrown).


    Parameters

    Returns string

    The name of the HF

getMaxListeners

  • getMaxListeners(): number
  • Returns number

publicgteHardfork

  • gteHardfork(hardfork: string): boolean
  • Alias to hardforkGteHardfork when hardfork is set


    Parameters

    • hardfork: string

      Hardfork name

    Returns boolean

    True if hardfork set is greater than hardfork provided

publichardfork

  • hardfork(): string
  • Returns the hardfork set


    Returns string

    Hardfork name

publichardforkBlock

  • hardforkBlock(_hardfork?: string): null | bigint
  • Returns the hardfork change block for hardfork provided or set


    Parameters

    • optional_hardfork: string

    Returns null | bigint

    Block number or null if unscheduled

publichardforkForForkHash


  • Parameters

    • forkHash: string

      Fork hash as a hex string

    Returns null | HardforkConfig

    Array with hardfork data (name, block, forkHash)

publichardforkGteHardfork

  • hardforkGteHardfork(_hardfork1: null | string, hardfork2: string): boolean
  • Sequence based check if given or set HF1 is greater than or equal HF2


    Parameters

    • _hardfork1: null | string
    • hardfork2: string

      Hardfork name

    Returns boolean

    True if HF1 gte HF2

publichardforkIsActiveOnBlock

  • hardforkIsActiveOnBlock(_hardfork: null | string, _blockNumber: Numbers): boolean
  • Checks if set or provided hardfork is active on block number


    Parameters

    • _hardfork: null | string
    • _blockNumber: Numbers

    Returns boolean

    True if HF is active on block number

publichardforkTTD

  • hardforkTTD(_hardfork?: string): null | bigint
  • Returns the hardfork change total difficulty (Merge HF) for hardfork provided or set


    Parameters

    • optional_hardfork: string

    Returns null | bigint

    Total difficulty or null if no set

publichardforkTimestamp

  • hardforkTimestamp(_hardfork?: string): null | bigint
  • Parameters

    • optional_hardfork: string

    Returns null | bigint

publichardforks

  • Returns the hardforks for current chain


    Returns HardforkConfig[]

    Array with arrays of hardforks

publicisActivatedEIP

  • isActivatedEIP(eip: number): boolean
  • Checks if an EIP is activated by either being included in the EIPs manually passed in with the CommonOpts.eips or in a hardfork currently being active

    Note: this method only works for EIPs being supported by the CommonOpts.eips constructor option


    Parameters

    • eip: number

    Returns boolean

publicisHardforkBlock

  • isHardforkBlock(_blockNumber: Numbers, _hardfork?: string): boolean
  • True if block number provided is the hardfork (given or set) change block

    @deprecated

    Parameters

    • _blockNumber: Numbers
    • optional_hardfork: string

    Returns boolean

    True if blockNumber is HF block

publicisNextHardforkBlock

  • isNextHardforkBlock(_blockNumber: Numbers, _hardfork?: string): boolean
  • True if block number provided is the hardfork change block following the hardfork given or set

    @deprecated

    Parameters

    • _blockNumber: Numbers
    • optional_hardfork: string

    Returns boolean

    True if blockNumber is HF block

publicnetworkId

  • networkId(): bigint
  • Returns the Id of current network


    Returns bigint

    network Id

publicnextHardforkBlock

  • nextHardforkBlock(_hardfork?: string): null | bigint
  • Returns the change block for the next hardfork after the hardfork provided or set

    @deprecated

    Parameters

    • optional_hardfork: string

    Returns null | bigint

    Block number or null if not available

publicnextHardforkBlockOrTimestamp

  • nextHardforkBlockOrTimestamp(_hardfork?: string): null | bigint
  • Returns the change block for the next hardfork after the hardfork provided or set


    Parameters

    • optional_hardfork: string

    Returns null | bigint

    Block timestamp, number or null if not available

publicparam

  • param(topic: string, name: string): bigint
  • Returns a parameter for the current chain setup

    If the parameter is present in an EIP, the EIP always takes precedence. Otherwise the parameter if taken from the latest applied HF with a change on the respective parameter.


    Parameters

    • topic: string

      Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow')

    • name: string

      Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic)

    Returns bigint

    The value requested or BigInt(0) if not found

publicparamByBlock

  • paramByBlock(topic: string, name: string, blockNumber: Numbers, td?: Numbers, timestamp?: Numbers): bigint
  • Returns a parameter for the hardfork active on block number or optional provided total difficulty (Merge HF)


    Parameters

    • topic: string

      Parameter topic

    • name: string

      Parameter name

    • blockNumber: Numbers

      Block number

    • optionaltd: Numbers

      Total difficulty *

    • optionaltimestamp: Numbers

    Returns bigint

    The value requested or BigInt(0) if not found

publicparamByEIP

  • paramByEIP(topic: string, name: string, eip: number): undefined | bigint
  • Returns a parameter corresponding to an EIP


    Parameters

    • topic: string

      Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow')

    • name: string

      Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic)

    • eip: number

      Number of the EIP

    Returns undefined | bigint

    The value requested or undefined if not found

publicparamByHardfork

  • paramByHardfork(topic: string, name: string, hardfork: string): bigint
  • Returns the parameter corresponding to a hardfork


    Parameters

    • topic: string

      Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow')

    • name: string

      Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic)

    • hardfork: string

      Hardfork name

    Returns bigint

    The value requested or BigInt(0) if not found

publicsetChain

  • setChain(chain: string | number | bigint | object): ChainConfig
  • Sets the chain


    Parameters

    • chain: string | number | bigint | object

      String ('mainnet') or Number (1) chain representation. Or, a Dictionary of chain parameters for a private network.

    Returns ChainConfig

    The dictionary with parameters set as chain

publicsetEIPs

  • setEIPs(eips?: number[]): void
  • Sets the active EIPs


    Parameters

    • eips: number[] = []

    Returns void

publicsetForkHashes

  • setForkHashes(genesisHash: Uint8Array): void
  • Sets any missing forkHashes on the passed-in Common instance


    Parameters

    • genesisHash: Uint8Array

      The genesis block hash

    Returns void

publicsetHardfork

  • setHardfork(hardfork: string): void
  • Sets the hardfork to get params for


    Parameters

    • hardfork: string

      String identifier (e.g. 'byzantium') or Hardfork enum

    Returns void

publicsetHardforkByBlockNumber

  • Sets a new hardfork based on the block number or an optional total difficulty (Merge HF) provided.

    An optional TD takes precedence in case the corresponding HF block is set to null or otherwise needs to match (if not an error will be thrown).


    Parameters

    Returns string

    The name of the HF set

setMaxListeners

  • setMaxListeners(maxListeners: number): this
  • Parameters

    • maxListeners: number

    Returns this

publicstatic_getInitializedChains

publicstaticcustom

  • Creates a Common object for a custom chain, based on a standard one.

    It uses all the Chain parameters from the baseChain option except the ones overridden in a provided chainParamsOrName dictionary. Some usage example:

    Common.custom({chainId: 123})

    There are also selected supported custom chains which can be initialized by using one of the CustomChains for chainParamsOrName, e.g.:

    Common.custom(CustomChains.MaticMumbai)

    Note that these supported custom chains only provide some base parameters (usually the chain and network ID and a name) and can only be used for selected use cases (e.g. sending a tx with the web3-utils/tx library to a Layer-2 chain).


    Parameters

    • chainParamsOrName: Partial<ChainConfig> | CustomChain

      Custom parameter dict (name will default to custom-chain) or string with name of a supported custom chain

    • opts: CustomCommonOpts = {}

      Custom chain options to set the CustomCommonOpts.baseChain, selected CustomCommonOpts.hardfork and others

    Returns Common

publicstaticfromGethGenesis

  • Static method to load and set common from a geth genesis json


    Parameters

    • genesisJson: any

      json of geth configuration

    • to: GethConfigOpts

      further configure the common instance

    Returns Common

    Common

publicstaticisSupportedChainId

  • isSupportedChainId(chainId: bigint): boolean
  • Static method to determine if a chainId is supported as a standard chain


    Parameters

    • chainId: bigint

      bigint id (1) of a standard chain

    Returns boolean

    boolean