import { EventEmitter } from 'events' ; import { buf as crc32Buffer } from 'crc-32' ; import { BN , BNLike , toType , TypeOutput , intToBuffer } from 'ethereumjs-util' ; import { _getInitializedChains } from './chains' ; import { hardforks as HARDFORK_CHANGES } from './hardforks' ; import { EIPs } from './eips' ; import { BootstrapNode , Chain as IChain , GenesisBlock , GenesisState , Hardfork as HardforkParams , } from './types' ; export enum CustomChain { /**
     * Polygon (Matic) Mainnet
     *
     * - [Documentation](https://docs.matic.network/docs/develop/network-details/network)
     */ PolygonMainnet = 'polygon-mainnet' , /**
     * Polygon (Matic) Mumbai Testnet
     *
     * - [Documentation](https://docs.matic.network/docs/develop/network-details/network)
     */ PolygonMumbai = 'polygon-mumbai' , /**
     * Arbitrum Rinkeby Testnet
     *
     * - [Documentation](https://developer.offchainlabs.com/docs/public_testnet)
     */ ArbitrumRinkebyTestnet = 'arbitrum-rinkeby-testnet' , /**
     * xDai EVM sidechain with a native stable token
     *
     * - [Documentation](https://www.xdaichain.com/)
     */ xDaiChain = 'x-dai-chain' , /**
     * Optimistic Kovan - testnet for Optimism roll-up
     *
     * - [Documentation](https://community.optimism.io/docs/developers/tutorials.html)
     */ OptimisticKovan = 'optimistic-kovan' , /**
     * Optimistic Ethereum - mainnet for Optimism roll-up
     *
     * - [Documentation](https://community.optimism.io/docs/developers/tutorials.html)
     */ OptimisticEthereum = 'optimistic-ethereum' } export enum Chain { Mainnet = 1 , Ropsten = 3 , Rinkeby = 4 , Kovan = 42 , Goerli = 5 , Sepolia = 11155111 } export enum Hardfork { Chainstart = 'chainstart' , Homestead = 'homestead' , Dao = 'dao' , TangerineWhistle = 'tangerineWhistle' , SpuriousDragon = 'spuriousDragon' , Byzantium = 'byzantium' , Constantinople = 'constantinople' , Petersburg = 'petersburg' , Istanbul = 'istanbul' , MuirGlacier = 'muirGlacier' , Berlin = 'berlin' , London = 'london' , ArrowGlacier = 'arrowGlacier' , Shanghai = 'shanghai' , Merge = 'merge' } export enum ConsensusType { ProofOfStake = 'pos' , ProofOfWork = 'pow' , ProofOfAuthority = 'poa' } export enum ConsensusAlgorithm { Ethash = 'ethash' , Clique = 'clique' , Casper = 'casper' } interface BaseOpts { /**
     * String identifier ('byzantium') for hardfork or  Hardfork enum.
     *
     * Default: Hardfork.Istanbul
      hardfork ? : string | Hardfork ; /**
     * Limit parameter returns to the given hardforks
     */ supportedHardforks ? : Array < string | Hardfork > ; /**
     * Selected EIPs which can be activated, please use an array for instantiation
     * (e.g. `eips: [ 2537, ]`)
     *
     * Currently supported:
     *
     * - [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537) - BLS12-381 precompiles
     */ eips ? : number [ ] ; } /**
 * Options for instantiating a  Common instance.
  export interface CommonOpts extends BaseOpts { /**
     * Chain name ('mainnet'), id (1), or  Chain enum,
     * either from a chain directly supported or a custom chain
     * passed in via  CommonOpts . customChains .
      chain : string | number | Chain | BN | object ; /**
     * Initialize (in addition to the supported chains) with the selected
     * custom chains
     *
     * Usage (directly with the respective chain intialization via the  CommonOpts . chain option):
     *
     * Pattern 1 (without genesis state):
     *
     * ```javascript
     * import myCustomChain1 from '[PATH_TO_MY_CHAINS]/myCustomChain1.json'
     * const common = new Common({ chain: 'myCustomChain1', customChains: [ myCustomChain1 ]})
     * ```
     *
     * Pattern 2 (with genesis state, see  GenesisState for format):
     *
     * ```javascript
     * import myCustomChain1 from '[PATH_TO_MY_CHAINS]/myCustomChain1.json'
     * import chain1GenesisState from '[PATH_TO_GENESIS_STATES]/chain1GenesisState.json'
     * const common = new Common({ chain: 'myCustomChain1', customChains: [ [ myCustomChain1, chain1GenesisState ] ]})
     * ```
      customChains ? : IChain [ ] | [ IChain , GenesisState ] [ ] ; } /**
 * Options to be used with the  Common . custom static constructor.
  export interface CustomCommonOpts extends BaseOpts { /**
     * The name (`mainnet`), id (`1`), or  Chain enum of
     * a standard chain used to base the custom chain params on.
      baseChain ? : string | number | Chain | BN ; } interface hardforkOptions { /** optional, only allow supported HFs (default: false) */ onlySupported ? : boolean ; /** optional, only active HFs (default: false) */ onlyActive ? : 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).
  export default class Common extends EventEmitter { readonly DEFAULT_HARDFORK : string | Hardfork ; private _chainParams : IChain ; private _hardfork : string | Hardfork ; private _supportedHardforks : Array < string | Hardfork > = [ ] ; private _eips : number [ ] = [ ] ; private _customChains : IChain [ ] | [ IChain , GenesisState ] [ ] ; /**
     * 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:
     *
     * ```javascript
     * 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.:
     *
     * ```javascript
     * 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).
     *
     *  param chainParamsOrName param opts Custom chain options to set the  CustomCommonOpts . baseChain , selected  CustomCommonOpts . hardfork and others
      static custom ( chainParamsOrName , opts = { } ) { const baseChain = opts . baseChain ?? 'mainnet' ; const standardChainParams = { ... Common . _getChainParams ( baseChain ) } ; standardChainParams [ 'name' ] = 'custom-chain' ; if ( typeof chainParamsOrName !== 'string' ) { return new Common ( { chain : { ... standardChainParams , ... chainParamsOrName , } , ... opts , } ) ; } else { if ( chainParamsOrName === CustomChain . PolygonMainnet ) { return Common . custom ( { name : CustomChain . PolygonMainnet , chainId : 137 , networkId : 137 , } ) ; } if ( chainParamsOrName === CustomChain . PolygonMumbai ) { return Common . custom ( { name : CustomChain . PolygonMumbai , chainId : 80001 , networkId : 80001 , } ) ; } if ( chainParamsOrName === CustomChain . ArbitrumRinkebyTestnet ) { return Common . custom ( { name : CustomChain . ArbitrumRinkebyTestnet , chainId : 421611 , networkId : 421611 , } ) ; } if ( chainParamsOrName === CustomChain . xDaiChain ) { return Common . custom ( { name : CustomChain . xDaiChain , chainId : 100 , networkId : 100 , } ) ; } if ( chainParamsOrName === CustomChain . OptimisticKovan ) { return Common . custom ( { name : CustomChain . OptimisticKovan , chainId : 69 , networkId : 69 , } , { hardfork : Hardfork . Berlin } ) ; } if ( chainParamsOrName === CustomChain . OptimisticEthereum ) { return Common . custom ( { name : CustomChain . OptimisticEthereum , chainId : 10 , networkId : 10 , } , { hardfork : Hardfork . Berlin } ) ; } throw new Error ( `Custom chain ${ chainParamsOrName } not supported` ) ; } } /**
     * Creates a  Common object for a custom chain, based on a standard one. It uses all the `Chain`
     * params from  baseChain except the ones overridden in  customChainParams .
     *
     *  deprecated Use  Common . custom instead
     *
     *  param baseChain param customChainParams param hardfork param supportedHardforks static forCustomChain ( baseChain , customChainParams , hardfork ? , supportedHardforks ? ) { const standardChainParams = Common . _getChainParams ( baseChain ) ; return new Common ( { chain : { ... standardChainParams , ... customChainParams , } , hardfork : hardfork , supportedHardforks : supportedHardforks , } ) ; } /**
     * Static method to determine if a  chainId is supported as a standard chain
     *  param chainId returns static isSupportedChainId ( chainId ) { const initializedChains = _getInitializedChains ( ) ; return Boolean ( initializedChains [ 'names' ] [ chainId . toString ( ) ] ) ; } private static _getChainParams ( chain , customChains ? ) { const initializedChains = _getInitializedChains ( customChains ) ; if ( typeof chain === 'number' || BN . isBN ( chain ) ) { chain = chain . toString ( ) ; if ( initializedChains [ 'names' ] [ chain ] ) { const name = initializedChains [ 'names' ] [ chain ] ; return initializedChains [ name ] ; } throw new Error ( `Chain with ID ${ chain } not supported` ) ; } if ( initializedChains [ chain ] ) { return initializedChains [ chain ] ; } throw new Error ( `Chain with name ${ chain } not supported` ) ; } constructor constructor ( opts ) { super ( ) ; this . _customChains = opts . customChains ?? [ ] ; this . _chainParams = this . setChain ( opts . chain ) ; this . DEFAULT_HARDFORK = this . _chainParams . defaultHardfork ?? Hardfork . Istanbul ; for ( const hf of this . _chainParams . hardforks ) { if ( ! hf . forkHash ) { hf . forkHash = this . _calcForkHash ( hf . name ) ; } } this . _hardfork = this . DEFAULT_HARDFORK ; if ( opts . supportedHardforks ) { this . _supportedHardforks = opts . supportedHardforks ; } if ( opts . hardfork ) { this . setHardfork ( opts . hardfork ) ; } if ( opts . eips ) { this . setEIPs ( opts . eips ) ; } } param chain returns setChain ( chain ) { if ( typeof chain === 'number' || typeof chain === 'string' || BN . isBN ( chain ) ) { let plainCustomChains ; if ( this . _customChains && this . _customChains . length > 0 && Array . isArray ( this . _customChains [ 0 ] ) ) { plainCustomChains = ( this . _customChains as [ IChain , GenesisState ] [ ] ) . map ( ( e ) => e [ 0 ] ) ; } else { plainCustomChains = this . _customChains as IChain [ ] ; } this . _chainParams = Common . _getChainParams ( chain , plainCustomChains ) ; } else if ( typeof chain === 'object' ) { if ( this . _customChains . length > 0 ) { throw new Error ( 'Chain must be a string, number, or BN when initialized with customChains passed in' ) ; } const required = [ 'networkId' , 'genesis' , 'hardforks' , 'bootstrapNodes' ] ; for ( const param of required ) { if ( ( < any > chain ) [ param ] === undefined ) { throw new Error ( `Missing required chain parameter: ${ param }` ) ; } } this . _chainParams = chain as IChain ; } else { throw new Error ( 'Wrong input format' ) ; } return this . _chainParams ; } param hardfork String identifier (e.g. 'byzantium') or  Hardfork enum
      setHardfork ( hardfork ) { if ( ! this . _isSupportedHardfork ( hardfork ) ) { throw new Error ( `Hardfork ${ hardfork } not set as supported in supportedHardforks` ) ; } let existing = false ; for ( const hfChanges of HARDFORK_CHANGES ) { if ( hfChanges [ 0 ] === hardfork ) { if ( this . _hardfork !== hardfork ) { this . _hardfork = hardfork ; this . emit ( 'hardforkChanged' , hardfork ) ; } existing = true ; } } if ( ! existing ) { throw new Error ( `Hardfork with name ${ hardfork } not supported` ) ; } } param blockNumber param td returns getHardforkByBlockNumber ( blockNumber , td ? ) { blockNumber = toType ( blockNumber , TypeOutput . BN ) ; td = toType ( td , TypeOutput . BN ) ; let hardfork = Hardfork . Chainstart ; let minTdHF ; let maxTdHF ; let previousHF ; for ( const hf of this . hardforks ( ) ) { if ( hf . block === null ) { if ( td !== undefined && td !== null && hf . td !== undefined && hf . td !== null ) { if ( td . gte ( new BN ( hf . td ) ) ) { return hf . name ; } } continue ; } if ( blockNumber . gte ( new BN ( hf . block ) ) ) { hardfork = hf . name as Hardfork ; } if ( td && hf . td ) { if ( td . gte ( new BN ( hf . td ) ) ) { minTdHF = hf . name ; } else { maxTdHF = previousHF ; } } previousHF = hf . name ; } if ( td ) { let msgAdd = `block number: ${ blockNumber } (-> ${ hardfork }), ` ; if ( minTdHF ) { if ( ! this . hardforkGteHardfork ( hardfork , minTdHF ) ) { const msg = 'HF determined by block number is lower than the minimum total difficulty HF' ; msgAdd += `total difficulty: ${ td } (-> ${ minTdHF })` ; throw new Error ( `${ msg }: ${ msgAdd }` ) ; } } if ( maxTdHF ) { if ( ! this . hardforkGteHardfork ( maxTdHF , hardfork ) ) { const msg = 'Maximum HF determined by total difficulty is lower than the block number HF' ; msgAdd += `total difficulty: ${ td } (-> ${ maxTdHF })` ; throw new Error ( `${ msg }: ${ msgAdd }` ) ; } } } return hardfork ; } param blockNumber param td returns setHardforkByBlockNumber ( blockNumber , td ? ) { const hardfork = this . getHardforkByBlockNumber ( blockNumber , td ) ; this . setHardfork ( hardfork ) ; return hardfork ; } param hardfork returns _chooseHardfork ( hardfork ? , onlySupported = true ) { if ( ! hardfork ) { hardfork = this . _hardfork ; } else if ( onlySupported && ! this . _isSupportedHardfork ( hardfork ) ) { throw new Error ( `Hardfork ${ hardfork } not set as supported in supportedHardforks` ) ; } return hardfork ; } param hardfork returns _getHardfork ( hardfork ) { const hfs = this . hardforks ( ) ; for ( const hf of hfs ) { if ( hf [ 'name' ] === hardfork ) return hf ; } throw new Error ( `Hardfork ${ hardfork } not defined for chain ${ this . chainName ( ) }` ) ; } param hardfork returns _isSupportedHardfork ( hardfork ) { if ( this . _supportedHardforks . length > 0 ) { for ( const supportedHf of this . _supportedHardforks ) { if ( hardfork === supportedHf ) return true ; } } else { return true ; } return false ; } param eips setEIPs ( eips = [ ] ) { for ( const eip of eips ) { if ( ! ( eip in EIPs ) ) { throw new Error ( `${ eip } not supported` ) ; } const minHF = this . gteHardfork ( EIPs [ eip ] [ 'minimumHardfork' ] ) ; if ( ! minHF ) { throw new Error ( `${ eip } cannot be activated on hardfork ${ this . hardfork ( ) }, minimumHardfork: ${ minHF }` ) ; } if ( EIPs [ eip ] . requiredEIPs ) { ; ( EIPs [ eip ] . requiredEIPs as number [ ] ) . forEach ( ( elem ) => { if ( ! ( eips . includes ( elem ) || this . isActivatedEIP ( elem ) ) ) { throw new Error ( `${ eip } requires EIP ${ elem }, but is not included in the EIP list` ) ; } } ) ; } } this . _eips = eips ; } param topic param name returns param ( topic , name ) { let value = null ; for ( const eip of this . _eips ) { value = this . paramByEIP ( topic , name , eip ) ; if ( value !== null ) { return value ; } } return this . paramByHardfork ( topic , name , this . _hardfork ) ; } param topic param name param hardfork returns paramByHardfork ( topic , name , hardfork ) { hardfork = this . _chooseHardfork ( hardfork ) ; let value = null ; for ( const hfChanges of HARDFORK_CHANGES ) { if ( 'eips' in hfChanges [ 1 ] ) { const hfEIPs = hfChanges [ 1 ] [ 'eips' ] ; for ( const eip of hfEIPs ) { const valueEIP = this . paramByEIP ( topic , name , eip ) ; value = valueEIP !== null ? valueEIP : value ; } } else { if ( ! hfChanges [ 1 ] [ topic ] ) { throw new Error ( `Topic ${ topic } not defined` ) ; } if ( hfChanges [ 1 ] [ topic ] [ name ] !== undefined ) { value = hfChanges [ 1 ] [ topic ] [ name ] . v ; } } if ( hfChanges [ 0 ] === hardfork ) break ; } return value ; } param topic param name param eip returns paramByEIP ( topic , name , eip ) { if ( ! ( eip in EIPs ) ) { throw new Error ( `${ eip } not supported` ) ; } const eipParams = EIPs [ eip ] ; if ( ! ( topic in eipParams ) ) { throw new Error ( `Topic ${ topic } not defined` ) ; } if ( eipParams [ topic ] [ name ] === undefined ) { return null ; } const value = eipParams [ topic ] [ name ] . v ; return value ; } param topic param name param blockNumber paramByBlock ( topic , name , blockNumber ) { const activeHfs = this . activeHardforks ( blockNumber ) ; const hardfork = activeHfs [ activeHfs . length - 1 ] [ 'name' ] ; return this . paramByHardfork ( topic , name , hardfork ) ; } /**
     * 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
     *  param eip isActivatedEIP ( eip ) { if ( this . eips ( ) . includes ( eip ) ) { return true ; } for ( const hfChanges of HARDFORK_CHANGES ) { const hf = hfChanges [ 1 ] ; if ( this . gteHardfork ( hf [ 'name' ] ) && 'eips' in hf ) { if ( hf [ 'eips' ] . includes ( eip ) ) { return true ; } } } return false ; } param hardfork param blockNumber param opts returns hardforkIsActiveOnBlock ( hardfork , blockNumber , opts = { } ) { blockNumber = toType ( blockNumber , TypeOutput . BN ) ; const onlySupported = opts . onlySupported ?? false ; hardfork = this . _chooseHardfork ( hardfork , onlySupported ) ; const hfBlock = this . hardforkBlockBN ( hardfork ) ; if ( hfBlock && blockNumber . gte ( hfBlock ) ) { return true ; } return false ; } param blockNumber param opts returns activeOnBlock ( blockNumber , opts ? ) { return this . hardforkIsActiveOnBlock ( null , blockNumber , opts ) ; } param hardfork1 param hardfork2 param opts returns hardforkGteHardfork ( hardfork1 , hardfork2 , opts = { } ) { const onlyActive = opts . onlyActive === undefined ? false : opts . onlyActive ; hardfork1 = this . _chooseHardfork ( hardfork1 , opts . onlySupported ) ; let hardforks ; if ( onlyActive ) { hardforks = this . activeHardforks ( null , opts ) ; } else { hardforks = this . hardforks ( ) ; } let posHf1 = - 1 , posHf2 = - 1 ; let index = 0 ; for ( const hf of hardforks ) { if ( hf [ 'name' ] === hardfork1 ) posHf1 = index ; if ( hf [ 'name' ] === hardfork2 ) posHf2 = index ; index += 1 ; } return posHf1 >= posHf2 && posHf2 !== - 1 ; } param hardfork param opts returns gteHardfork ( hardfork , opts ? ) { return this . hardforkGteHardfork ( null , hardfork , opts ) ; } param hardfork param opts returns hardforkIsActiveOnChain ( hardfork ? , opts = { } ) { const onlySupported = opts . onlySupported ?? false ; hardfork = this . _chooseHardfork ( hardfork , onlySupported ) ; for ( const hf of this . hardforks ( ) ) { if ( hf [ 'name' ] === hardfork && hf [ 'block' ] !== null ) return true ; } return false ; } param blockNumber param opts return activeHardforks ( blockNumber ? , opts = { } ) { const activeHardforks = [ ] ; const hfs = this . hardforks ( ) ; for ( const hf of hfs ) { if ( hf [ 'block' ] === null ) continue ; if ( blockNumber !== undefined && blockNumber !== null && blockNumber < hf [ 'block' ] ) break ; if ( opts . onlySupported && ! this . _isSupportedHardfork ( hf [ 'name' ] ) ) continue ; activeHardforks . push ( hf ) ; } return activeHardforks ; } param blockNumber param opts return activeHardfork ( blockNumber ? , opts = { } ) { const activeHardforks = this . activeHardforks ( blockNumber , opts ) ; if ( activeHardforks . length > 0 ) { return activeHardforks [ activeHardforks . length - 1 ] [ 'name' ] ; } else { throw new Error ( `No (supported) active hardfork found` ) ; } } param hardfork returns deprecated Please use  Common . hardforkBlockBN for large number support
      hardforkBlock ( hardfork ? ) { const block = this . hardforkBlockBN ( hardfork ) ; return toType ( block , TypeOutput . Number ) ; } param hardfork returns hardforkBlockBN ( hardfork ? ) { hardfork = this . _chooseHardfork ( hardfork , false ) ; const block = this . _getHardfork ( hardfork ) [ 'block' ] ; if ( block === undefined || block === null ) { return null ; } return new BN ( block ) ; } param hardfork returns hardforkTD ( hardfork ? ) { hardfork = this . _chooseHardfork ( hardfork , false ) ; const td = this . _getHardfork ( hardfork ) [ 'td' ] ; if ( td === undefined || td === null ) { return null ; } return new BN ( td ) ; } param blockNumber param hardfork returns isHardforkBlock ( blockNumber , hardfork ? ) { blockNumber = toType ( blockNumber , TypeOutput . BN ) ; hardfork = this . _chooseHardfork ( hardfork , false ) ; const block = this . hardforkBlockBN ( hardfork ) ; return block ? block . eq ( blockNumber ) : false ; } param hardfork returns deprecated Please use  Common . nextHardforkBlockBN for large number support
      nextHardforkBlock ( hardfork ? ) { const block = this . nextHardforkBlockBN ( hardfork ) ; return toType ( block , TypeOutput . Number ) ; } param hardfork returns nextHardforkBlockBN ( hardfork ? ) { hardfork = this . _chooseHardfork ( hardfork , false ) ; const hfBlock = this . hardforkBlockBN ( hardfork ) ; if ( hfBlock === null ) { return null ; } const nextHfBlock = this . hardforks ( ) . reduce ( ( acc , hf ) => { const block = new BN ( hf . block ! ) ; return block . gt ( hfBlock ) && acc === null ? block : acc ; } , null ) ; return nextHfBlock ; } param blockNumber param hardfork returns isNextHardforkBlock ( blockNumber , hardfork ? ) { blockNumber = toType ( blockNumber , TypeOutput . BN ) ; hardfork = this . _chooseHardfork ( hardfork , false ) ; const nextHardforkBlock = this . nextHardforkBlockBN ( hardfork ) ; return nextHardforkBlock === null ? false : nextHardforkBlock . eq ( blockNumber ) ; } param hardfork returns _calcForkHash ( hardfork ) { const genesis = Buffer . from ( this . genesis ( ) . hash . substr ( 2 ) , 'hex' ) ; let hfBuffer = Buffer . alloc ( 0 ) ; let prevBlock = 0 ; for ( const hf of this . hardforks ( ) ) { const block = hf . block ; if ( block !== 0 && block !== null && block !== prevBlock ) { const hfBlockBuffer = Buffer . from ( block . toString ( 16 ) . padStart ( 16 , '0' ) , 'hex' ) ; hfBuffer = Buffer . concat ( [ hfBuffer , hfBlockBuffer ] ) ; } if ( hf . name === hardfork ) break ; if ( block !== null ) { prevBlock = block ; } } const inputBuffer = Buffer . concat ( [ genesis , hfBuffer ] ) ; const forkhash = intToBuffer ( crc32Buffer ( inputBuffer ) >>> 0 ) . toString ( 'hex' ) ; return `0x${ forkhash }` ; } param hardfork forkHash ( hardfork ? ) { hardfork = this . _chooseHardfork ( hardfork , false ) ; const data = this . _getHardfork ( hardfork ) ; if ( data [ 'block' ] === null && data [ 'td' ] === undefined ) { const msg = 'No fork hash calculation possible for future hardfork' ; throw new Error ( msg ) ; } if ( data [ 'forkHash' ] !== undefined ) { return data [ 'forkHash' ] ; } return this . _calcForkHash ( hardfork ) ; } param forkHash returns hardforkForForkHash ( forkHash ) { const resArray = this . hardforks ( ) . filter ( ( hf ) => { return hf . forkHash === forkHash ; } ) ; return resArray . length >= 1 ? resArray [ resArray . length - 1 ] : null ; } returns genesis ( ) { return this . _chainParams [ 'genesis' ] ; } /**
     * Returns the Genesis state of the current chain,
     * all values are provided as hex-prefixed strings.
     */ genesisState ( ) { switch ( this . chainName ( ) ) { case 'mainnet' : return require ( './genesisStates/mainnet.json' ) ; case 'ropsten' : return require ( './genesisStates/ropsten.json' ) ; case 'rinkeby' : return require ( './genesisStates/rinkeby.json' ) ; case 'kovan' : return require ( './genesisStates/kovan.json' ) ; case 'goerli' : return require ( './genesisStates/goerli.json' ) ; case 'sepolia' : return require ( './genesisStates/sepolia.json' ) ; } if ( this . _customChains && this . _customChains . length > 0 && Array . isArray ( this . _customChains [ 0 ] ) ) { for ( const chainArrayWithGenesis of this . _customChains as [ IChain , GenesisState ] [ ] ) { if ( chainArrayWithGenesis [ 0 ] . name === this . chainName ( ) ) { return chainArrayWithGenesis [ 1 ] ; } } } return { } ; } returns { Array } hardforks ( ) { return this . _chainParams [ 'hardforks' ] ; } returns { Dictionary } bootstrapNodes ( ) { return this . _chainParams [ 'bootstrapNodes' ] ; } returns { String [ ] } dnsNetworks ( ) { return this . _chainParams [ 'dnsNetworks' ] ! ; } returns hardfork ( ) { return this . _hardfork ; } returns deprecated Please use  Common . chainIdBN for large number support
      chainId ( ) { return toType ( this . chainIdBN ( ) , TypeOutput . Number ) ; } returns chainIdBN ( ) { return new BN ( this . _chainParams [ 'chainId' ] ) ; } returns chainName ( ) { return this . _chainParams [ 'name' ] ; } returns deprecated Please use  Common . networkIdBN for large number support
      networkId ( ) { return toType ( this . networkIdBN ( ) , TypeOutput . Number ) ; } returns networkIdBN ( ) { return new BN ( this . _chainParams [ 'networkId' ] ) ; } returns eips ( ) { return this . _eips ; } /**
     * Returns the consensus type of the network
     * Possible values: "pow"|"poa"|"pos"
     *
     * Note: This value can update along a hardfork.
     */ consensusType ( ) { const hardfork = this . hardfork ( ) ; let value ; for ( const hfChanges of HARDFORK_CHANGES ) { if ( 'consensus' in hfChanges [ 1 ] ) { value = hfChanges [ 1 ] [ 'consensus' ] [ 'type' ] ; } if ( hfChanges [ 0 ] === hardfork ) break ; } if ( value ) { return value ; } return this . _chainParams [ 'consensus' ] ! [ 'type' ] ; } /**
     * 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.
     */ consensusAlgorithm ( ) { const hardfork = this . hardfork ( ) ; let value ; for ( const hfChanges of HARDFORK_CHANGES ) { if ( 'consensus' in hfChanges [ 1 ] ) { value = hfChanges [ 1 ] [ 'consensus' ] [ 'algorithm' ] ; } if ( hfChanges [ 0 ] === hardfork ) break ; } if ( value ) { return value ; } return this . _chainParams [ 'consensus' ] ! [ 'algorithm' ] as ConsensusAlgorithm ; } /**
     * 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: -
     * clique: period, epoch
     * aura: -
     * casper: -
     *
     * Note: This value can update along a hardfork.
     */ consensusConfig ( ) { const hardfork = this . hardfork ( ) ; let value ; for ( const hfChanges of HARDFORK_CHANGES ) { if ( 'consensus' in hfChanges [ 1 ] ) { value = hfChanges [ 1 ] [ 'consensus' ] [ hfChanges [ 1 ] [ 'consensus' ] [ 'algorithm' ] ] ; } if ( hfChanges [ 0 ] === hardfork ) break ; } if ( value ) { return value ; } const consensusAlgorithm = this . consensusAlgorithm ( ) ; return this . _chainParams [ 'consensus' ] ! [ consensusAlgorithm as ConsensusAlgorithm ] ; } /**
     * Returns a deep copy of this  Common instance.
      copy ( ) { return Object . assign ( Object . create ( Object . getPrototypeOf ( this ) ) , this ) ; } }