Common
Hierarchy
- EventEmitter
- Common
Index
Constructors
Properties
Methods
- _calcForkHash
- _getHardfork
- activeOnBlock
- bootstrapNodes
- chainId
- chainName
- consensusAlgorithm
- consensusConfig
- consensusType
- copy
- dnsNetworks
- eipBlock
- eips
- forkHash
- genesis
- getHardforkByBlockNumber
- getMaxListeners
- gteHardfork
- hardfork
- hardforkBlock
- hardforkForForkHash
- hardforkGteHardfork
- hardforkIsActiveOnBlock
- hardforkTTD
- hardforkTimestamp
- hardforks
- isActivatedEIP
- isHardforkBlock
- isNextHardforkBlock
- networkId
- nextHardforkBlock
- nextHardforkBlockOrTimestamp
- param
- paramByBlock
- paramByEIP
- paramByHardfork
- setChain
- setEIPs
- setForkHashes
- setHardfork
- setHardforkByBlockNumber
- setMaxListeners
- _getInitializedChains
- custom
- fromGethGenesis
- isSupportedChainId
Constructors
publicconstructor
Parameters
opts: CommonOpts
Returns Common
Properties
publicreadonlyDEFAULT_HARDFORK
Methods
public_calcForkHash
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
Alias to hardforkIsActiveOnBlock when hardfork is set
Parameters
blockNumber: Numbers
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
Returns the Id of current chain
Returns bigint
chain Id
publicchainName
Returns the name of current chain
Returns string
chain name (lower case)
publicconsensusAlgorithm
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
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 {}
[key string]: CliqueConfig | EthashConfig | CasperConfig
publicconsensusType
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
Returns DNS networks for the current chain
Returns string[]
Array of DNS ENR urls
publiceipBlock
Returns the hardfork change block for eip
Parameters
eip: number
EIP number
Returns null | bigint
Block number or null if unscheduled
publiceips
Returns the active EIPs
Returns number[]
List of EIPs
publicforkHash
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
Returns number
publicgteHardfork
Alias to hardforkGteHardfork when hardfork is set
Parameters
hardfork: string
Hardfork name
Returns boolean
True if hardfork set is greater than hardfork provided
publichardfork
Returns the hardfork set
Returns string
Hardfork name
publichardforkBlock
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
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
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
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
Parameters
optional_hardfork: string
Returns null | bigint
publichardforks
Returns the hardforks for current chain
Returns HardforkConfig[]
Array with arrays of hardforks
publicisActivatedEIP
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
True if block number provided is the hardfork (given or set) change block
Parameters
_blockNumber: Numbers
optional_hardfork: string
Returns boolean
True if blockNumber is HF block
publicisNextHardforkBlock
True if block number provided is the hardfork change block following the hardfork given or set
Parameters
_blockNumber: Numbers
optional_hardfork: string
Returns boolean
True if blockNumber is HF block
publicnetworkId
Returns the Id of current network
Returns bigint
network Id
publicnextHardforkBlock
Returns the change block for the next hardfork after the hardfork provided or set
Parameters
optional_hardfork: string
Returns null | bigint
Block number or null if not available
publicnextHardforkBlockOrTimestamp
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
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
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
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
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
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
Sets the active EIPs
Parameters
eips: number[] = []
Returns void
publicsetForkHashes
Sets any missing forkHashes on the passed-in Common instance
Parameters
genesisHash: Uint8Array
The genesis block hash
Returns void
publicsetHardfork
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
Parameters
maxListeners: number
Returns this
publicstatic_getInitializedChains
Parameters
optionalcustomChains: ChainConfig[]
Returns ChainsConfig
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 tocustom-chain
) or string with name of a supported custom chainopts: 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
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
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).