ethereumjs-common
Version:
Resources common to all Ethereum implementations
290 lines (164 loc) • 6.44 kB
Markdown
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
- [Common][1]
- [setChain][2]
- [setHardfork][3]
- [\_chooseHardfork][4]
- [\_getHardfork][5]
- [\_isSupportedHardfork][6]
- [param][7]
- [paramByBlock][8]
- [hardforkIsActiveOnBlock][9]
- [hardforkIsActiveOnChain][10]
- [activeHardforks][11]
- [activeHardfork][12]
- [hardforkBlock][13]
- [isHardforkBlock][14]
- [consensus][15]
- [finality][16]
- [genesis][17]
- [hardforks][18]
- [bootstrapNodes][19]
- [hardfork][20]
- [chainId][21]
- [chainName][22]
- [networkId][23]
## Common
Common class to access chain and hardfork parameters
**Parameters**
- `chain` **([String][24] \| [Number][25])** String ('mainnet') or Number (1) chain representation
- `hardfork` **[String][24]** String identifier ('byzantium') for hardfork (optional)
- `supportedHardforks` **[Array][26]** Limit parameter returns to the given hardforks (optional)
### setChain
Sets the chain
**Parameters**
- `chain` **([String][24] \| [Number][25])** String ('mainnet') or Number (1) chain representation
### setHardfork
Sets the hardfork to get params for
**Parameters**
- `hardfork` **[String][24]** String identifier ('byzantium')
### \_chooseHardfork
Internal helper function to choose between hardfork set and hardfork provided as param
**Parameters**
- `hardfork` **[String][24]** Hardfork given to function as a parameter
Returns **[String][24]** Hardfork chosen to be used
### \_getHardfork
Internal helper function, returns the params for the given hardfork for the chain set
**Parameters**
- `hardfork` **[String][24]** Hardfork name
Returns **Dictionary**
### \_isSupportedHardfork
Internal helper function to check if a hardfork is set to be supported by the library
**Parameters**
- `hardfork` **[String][24]** Hardfork name
Returns **[Boolean][27]** True if hardfork is supported
### param
Returns the parameter corresponding to a hardfork
**Parameters**
- `topic` **[String][24]** Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding')
- `name` **[String][24]** Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic)
- `hardfork` **[String][24]** Hardfork name, optional if hardfork set
### paramByBlock
Returns a parameter for the hardfork active on block number
**Parameters**
- `topic` **[String][24]** Parameter topic
- `name` **[String][24]** Parameter name
- `blockNumber` **[Number][25]** Block number
### hardforkIsActiveOnBlock
Checks if a hardfork is active for a given block number
**Parameters**
- `hardfork` **[String][24]** Hardfork name
- `blockNumber` **[Number][25]**
- `opts` **[Array][26]**
- `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false)
Returns **[Boolean][27]**
### hardforkIsActiveOnChain
Checks if the hardfork provided is active on the chain
**Parameters**
- `hardfork` **[String][24]**
- `opts` **[Array][26]**
- `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false)
Returns **[Boolean][27]**
### activeHardforks
Returns the active hardfork switches for the current chain
**Parameters**
- `blockNumber` **[Number][25]** up to block if provided, otherwise for the whole chain
- `opts` **[Array][26]**
- `opts.onlySupported` **Array.Boolean** optional, limit results to supported HFs (default: false)
Returns **[Array][26]** Array with hardfork arrays
### activeHardfork
Returns the latest active hardfork name for chain or block or throws if unavailable
**Parameters**
- `blockNumber` **[Number][25]** up to block if provided, otherwise for the whole chain
- `opts` **[Array][26]**
- `opts.onlySupported` **Array.Boolean** optional, limit results to supported HFs (default: false)
Returns **[String][24]** Hardfork name
### hardforkBlock
Returns the hardfork change block for the given hardfork
**Parameters**
- `hardfork` **[String][24]** Hardfork name
Returns **[Number][25]** Block number
### isHardforkBlock
True if block number provided is the hardfork change block of the current chain
**Parameters**
- `hardfork` **[String][24]** Hardfork name
- `blockNumber` **[Number][25]** Number of the block to check
Returns **[Boolean][27]**
### consensus
Provide the consensus type for the hardfork set or provided as param
**Parameters**
- `hardfork` **[String][24]** Hardfork name, optional if hardfork set
Returns **[String][24]** Consensus type (e.g. 'pow', 'poa')
### finality
Provide the finality type for the hardfork set or provided as param
**Parameters**
- `hardfork` **[String][24]** Hardfork name, optional if hardfork set
Returns **[String][24]** Finality type (e.g. 'pos', null of no finality)
### genesis
Returns the Genesis parameters of current chain
Returns **Dictionary** Genesis dict
### hardforks
Returns the hardforks for current chain
Returns **[Array][26]** Array with arrays of hardforks
### bootstrapNodes
Returns bootstrap nodes for the current chain
Returns **Dictionary** Dict with bootstrap nodes
### hardfork
Returns the hardfork set
Returns **[String][24]** Hardfork name
### chainId
Returns the Id of current chain
Returns **[Number][25]** chain Id
### chainName
Returns the name of current chain
Returns **[String][24]** chain name (lower case)
### networkId
Returns the Id of current network
Returns **[Number][25]** network Id
[1]: #common
[2]: #setchain
[3]: #sethardfork
[4]: #_choosehardfork
[5]: #_gethardfork
[6]: #_issupportedhardfork
[7]: #param
[8]: #parambyblock
[9]: #hardforkisactiveonblock
[10]: #hardforkisactiveonchain
[11]: #activehardforks
[12]: #activehardfork
[13]: #hardforkblock
[14]: #ishardforkblock
[15]: #consensus
[16]: #finality
[17]: #genesis
[18]: #hardforks
[19]: #bootstrapnodes
[20]: #hardfork
[21]: #chainid
[22]: #chainname
[23]: #networkid
[24]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[25]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[26]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[27]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean