@ethereumjs/common / 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 custom static constructor for creating simple custom chain Common objects (more complete custom chain setups can be created via the main constructor and the customChains parameter).
• new Common(opts
)
Name | Type |
---|---|
opts |
CommonOpts |
• Readonly
DEFAULT_HARDFORK: string
• Readonly
customCrypto: CustomCrypto
• events: EventEmitter
▸ activeOnBlock(blockNumber
): boolean
Alias to hardforkIsActiveOnBlock when hardfork is set
Name | Type |
---|---|
blockNumber |
BigIntLike |
boolean
True if HF is active on block number
▸ bootstrapNodes(): BootstrapNodeConfig
[]
Returns bootstrap nodes for the current chain
Dict with bootstrap nodes
▸ chainId(): bigint
Returns the Id of current chain
bigint
chain Id
▸ chainName(): string
Returns the name of current chain
string
chain name (lower case)
▸ 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.
string
▸ consensusConfig(): Object
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.
Object
▸ consensusType(): string
Returns the consensus type of the network Possible values: “pow”|”poa”|”pos”
Note: This value can update along a Hardfork.
string
▸ copy(): Common
Returns a deep copy of this Common instance.
▸ dnsNetworks(): string
[]
Returns DNS networks for the current chain
string
[]
Array of DNS ENR urls
▸ eipBlock(eip
): null
| bigint
Returns the hardfork change block for eip
Name | Type | Description |
---|---|---|
eip |
number |
EIP number |
null
| bigint
Block number or null if unscheduled
▸ eipTimestamp(eip
): null
| bigint
Returns the scheduled timestamp of the EIP (if scheduled and scheduled by timestamp)
Name | Type | Description |
---|---|---|
eip |
number |
EIP number |
null
| bigint
Scheduled timestamp. If this EIP is unscheduled, or the EIP is scheduled by block number or ttd, then it returns null
.
▸ eips(): number
[]
Returns the additionally activated EIPs
(by using the eips
constructor option)
number
[]
List of EIPs
▸ forkHash(hardfork?
, genesisHash?
): string
Returns an eth/64 compliant fork hash (EIP-2124)
Name | Type | Description |
---|---|---|
hardfork? |
string |
Hardfork name, optional if HF set |
genesisHash? |
Uint8Array |
Genesis block hash of the chain, optional if already defined and not needed to be calculated |
string
▸ genesis(): GenesisBlockConfig
Returns the Genesis parameters of the current chain
Genesis dictionary
▸ getHardforkBy(opts
): string
Returns the hardfork either based on block numer (older HFs) or timestamp (Shanghai upwards).
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).
Name | Type |
---|---|
opts |
HardforkByOpts |
string
The name of the HF
▸ gteHardfork(hardfork
): boolean
Alias to hardforkGteHardfork when hardfork is set
Name | Type | Description |
---|---|---|
hardfork |
string |
Hardfork name |
boolean
True if hardfork set is greater than hardfork provided
▸ hardfork(): string
Returns the hardfork set
string
Hardfork name
▸ hardforkBlock(hardfork?
): null
| bigint
Returns the hardfork change block for hardfork provided or set
Name | Type | Description |
---|---|---|
hardfork? |
string |
Hardfork name, optional if HF set |
null
| bigint
Block number or null if unscheduled
▸ hardforkForForkHash(forkHash
): null
| HardforkTransitionConfig
Name | Type | Description |
---|---|---|
forkHash |
string |
Fork hash as a hex string |
null
| HardforkTransitionConfig
Array with hardfork data (name, block, forkHash)
▸ hardforkGteHardfork(hardfork1
, hardfork2
): boolean
Sequence based check if given or set HF1 is greater than or equal HF2
Name | Type | Description |
---|---|---|
hardfork1 |
null | string |
Hardfork name or null (if set) |
hardfork2 |
string |
Hardfork name |
boolean
True if HF1 gte HF2
▸ hardforkIsActiveOnBlock(hardfork
, blockNumber
): boolean
Checks if set or provided hardfork is active on block number
Name | Type | Description |
---|---|---|
hardfork |
null | string |
Hardfork name or null (for HF set) |
blockNumber |
BigIntLike |
boolean
True if HF is active on block number
▸ hardforkTTD(hardfork?
): null
| bigint
Returns the hardfork change total difficulty (Merge HF) for hardfork provided or set
Name | Type | Description |
---|---|---|
hardfork? |
string |
Hardfork name, optional if HF set |
null
| bigint
Total difficulty or null if no set
▸ hardforkTimestamp(hardfork?
): null
| bigint
Name | Type |
---|---|
hardfork? |
string |
null
| bigint
▸ hardforks(): HardforkTransitionConfig
[]
Returns the hardforks for current chain
Array with arrays of hardforks
▸ isActivatedEIP(eip
): boolean
Checks if an EIP is activated by either being included in the EIPs manually passed in with the eips or in a hardfork currently being active
Note: this method only works for EIPs being supported by the eips constructor option
Name | Type |
---|---|
eip |
number |
boolean
▸ networkId(): bigint
Returns the Id of current network
bigint
network Id
▸ nextHardforkBlockOrTimestamp(hardfork?
): null
| bigint
Returns the change block for the next hardfork after the hardfork provided or set
Name | Type | Description |
---|---|---|
hardfork? |
string |
Hardfork name, optional if HF set |
null
| bigint
Block timestamp, number or null if not available
▸ param(topic
, name
): 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 is taken from the latest applied HF with a change on the respective parameter.
Name | Type | Description |
---|---|---|
topic |
string |
Parameter topic (‘gasConfig’, ‘gasPrices’, ‘vm’, ‘pow’) |
name |
string |
Parameter name (e.g. ‘minGasLimit’ for ‘gasConfig’ topic) |
bigint
The value requested or BigInt(0)
if not found
▸ paramByBlock(topic
, name
, blockNumber
, td?
, timestamp?
): bigint
Returns a parameter for the hardfork active on block number or optional provided total difficulty (Merge HF)
Name | Type | Description |
---|---|---|
topic |
string |
Parameter topic |
name |
string |
Parameter name |
blockNumber |
BigIntLike |
Block number |
td? |
BigIntLike |
Total difficulty * |
timestamp? |
BigIntLike |
- |
bigint
The value requested or BigInt(0)
if not found
▸ paramByEIP(topic
, name
, eip
): undefined
| bigint
Returns a parameter corresponding to an EIP
Name | Type | Description |
---|---|---|
topic |
string |
Parameter topic (‘gasConfig’, ‘gasPrices’, ‘vm’, ‘pow’) |
name |
string |
Parameter name (e.g. ‘minGasLimit’ for ‘gasConfig’ topic) |
eip |
number |
Number of the EIP |
undefined
| bigint
The value requested or undefined
if not found
▸ paramByHardfork(topic
, name
, hardfork
): bigint
Returns the parameter corresponding to a hardfork
Name | Type | Description |
---|---|---|
topic |
string |
Parameter topic (‘gasConfig’, ‘gasPrices’, ‘vm’, ‘pow’) |
name |
string |
Parameter name (e.g. ‘minGasLimit’ for ‘gasConfig’ topic) |
hardfork |
string |
Hardfork name |
bigint
The value requested or BigInt(0)
if not found
▸ setChain(chain
): ChainConfig
Sets the chain
Name | Type | Description |
---|---|---|
chain |
string | number | bigint | object |
String (‘mainnet’) or Number (1) chain representation. Or, a Dictionary of chain parameters for a private network. |
The dictionary with parameters set as chain
▸ setEIPs(eips?
): void
Sets the active EIPs
Name | Type | Default value |
---|---|---|
eips |
number [] |
[] |
void
▸ setForkHashes(genesisHash
): void
Sets any missing forkHashes on the passed-in Common instance
Name | Type | Description |
---|---|---|
genesisHash |
Uint8Array |
The genesis block hash |
void
▸ setHardfork(hardfork
): void
Sets the hardfork to get params for
Name | Type | Description |
---|---|---|
hardfork |
string |
String identifier (e.g. ‘byzantium’) or Hardfork enum |
void
▸ setHardforkBy(opts
): string
Sets a new hardfork either based on block numer (older HFs) or timestamp (Shanghai upwards).
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).
Name | Type |
---|---|
opts |
HardforkByOpts |
string
The name of the HF set
▸ Static
custom(chainParamsOrName
, opts?
): Common
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 @ethereumjs/tx
library to a Layer-2 chain).
Name | Type | Description |
---|---|---|
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 baseChain, selected hardfork and others |
▸ Static
fromGethGenesis(genesisJson
, to
): Common
Static method to load and set common from a geth genesis json
Name | Type | Description |
---|---|---|
genesisJson |
any |
json of geth configuration |
to |
GethConfigOpts |
further configure the common instance |
Common
▸ Static
getInitializedChains(customChains?
): ChainsConfig
Name | Type |
---|---|
customChains? |
ChainConfig [] |
▸ Static
isSupportedChainId(chainId
): boolean
Static method to determine if a chainId is supported as a standard chain
Name | Type | Description |
---|---|---|
chainId |
bigint |
bigint id (1 ) of a standard chain |
boolean
boolean