@feelyourprotocol/common 8141.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +409 -0
- package/dist/cjs/chains.d.ts +6 -0
- package/dist/cjs/chains.d.ts.map +1 -0
- package/dist/cjs/chains.js +637 -0
- package/dist/cjs/chains.js.map +1 -0
- package/dist/cjs/common.d.ts +318 -0
- package/dist/cjs/common.d.ts.map +1 -0
- package/dist/cjs/common.js +789 -0
- package/dist/cjs/common.js.map +1 -0
- package/dist/cjs/constructors.d.ts +27 -0
- package/dist/cjs/constructors.d.ts.map +1 -0
- package/dist/cjs/constructors.js +53 -0
- package/dist/cjs/constructors.js.map +1 -0
- package/dist/cjs/crc.d.ts +8 -0
- package/dist/cjs/crc.d.ts.map +1 -0
- package/dist/cjs/crc.js +63 -0
- package/dist/cjs/crc.js.map +1 -0
- package/dist/cjs/eips.d.ts +3 -0
- package/dist/cjs/eips.d.ts.map +1 -0
- package/dist/cjs/eips.js +589 -0
- package/dist/cjs/eips.js.map +1 -0
- package/dist/cjs/enums.d.ts +65 -0
- package/dist/cjs/enums.d.ts.map +1 -0
- package/dist/cjs/enums.js +80 -0
- package/dist/cjs/enums.js.map +1 -0
- package/dist/cjs/gethGenesis.d.ts +145 -0
- package/dist/cjs/gethGenesis.d.ts.map +1 -0
- package/dist/cjs/gethGenesis.js +26 -0
- package/dist/cjs/gethGenesis.js.map +1 -0
- package/dist/cjs/hardforks.d.ts +3 -0
- package/dist/cjs/hardforks.d.ts.map +1 -0
- package/dist/cjs/hardforks.js +207 -0
- package/dist/cjs/hardforks.js.map +1 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interfaces.d.ts +132 -0
- package/dist/cjs/interfaces.d.ts.map +1 -0
- package/dist/cjs/interfaces.js +13 -0
- package/dist/cjs/interfaces.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types.d.ts +167 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.d.ts +60 -0
- package/dist/cjs/utils.d.ts.map +1 -0
- package/dist/cjs/utils.js +263 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/chains.d.ts +6 -0
- package/dist/esm/chains.d.ts.map +1 -0
- package/dist/esm/chains.js +634 -0
- package/dist/esm/chains.js.map +1 -0
- package/dist/esm/common.d.ts +318 -0
- package/dist/esm/common.d.ts.map +1 -0
- package/dist/esm/common.js +785 -0
- package/dist/esm/common.js.map +1 -0
- package/dist/esm/constructors.d.ts +27 -0
- package/dist/esm/constructors.d.ts.map +1 -0
- package/dist/esm/constructors.js +49 -0
- package/dist/esm/constructors.js.map +1 -0
- package/dist/esm/crc.d.ts +8 -0
- package/dist/esm/crc.d.ts.map +1 -0
- package/dist/esm/crc.js +59 -0
- package/dist/esm/crc.js.map +1 -0
- package/dist/esm/eips.d.ts +3 -0
- package/dist/esm/eips.d.ts.map +1 -0
- package/dist/esm/eips.js +586 -0
- package/dist/esm/eips.js.map +1 -0
- package/dist/esm/enums.d.ts +65 -0
- package/dist/esm/enums.d.ts.map +1 -0
- package/dist/esm/enums.js +77 -0
- package/dist/esm/enums.js.map +1 -0
- package/dist/esm/gethGenesis.d.ts +145 -0
- package/dist/esm/gethGenesis.d.ts.map +1 -0
- package/dist/esm/gethGenesis.js +23 -0
- package/dist/esm/gethGenesis.js.map +1 -0
- package/dist/esm/hardforks.d.ts +3 -0
- package/dist/esm/hardforks.d.ts.map +1 -0
- package/dist/esm/hardforks.js +204 -0
- package/dist/esm/hardforks.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interfaces.d.ts +132 -0
- package/dist/esm/interfaces.d.ts.map +1 -0
- package/dist/esm/interfaces.js +10 -0
- package/dist/esm/interfaces.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/types.d.ts +167 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.d.ts +60 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +258 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
- package/package.json +77 -0
- package/src/chains.ts +638 -0
- package/src/common.ts +913 -0
- package/src/constructors.ts +60 -0
- package/src/crc.ts +63 -0
- package/src/eips.ts +588 -0
- package/src/enums.ts +104 -0
- package/src/gethGenesis.ts +175 -0
- package/src/hardforks.ts +205 -0
- package/src/index.ts +8 -0
- package/src/interfaces.ts +191 -0
- package/src/types.ts +193 -0
- package/src/utils.ts +324 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
# @ethereumjs/common `v10`
|
|
2
|
+
|
|
3
|
+
[![NPM Package][common-npm-badge]][common-npm-link]
|
|
4
|
+
[![GitHub Issues][common-issues-badge]][common-issues-link]
|
|
5
|
+
[![Actions Status][common-actions-badge]][common-actions-link]
|
|
6
|
+
[![Code Coverage][common-coverage-badge]][common-coverage-link]
|
|
7
|
+
[![Discord][discord-badge]][discord-link]
|
|
8
|
+
|
|
9
|
+
| Resources common to all EthereumJS implementations. |
|
|
10
|
+
| --------------------------------------------------- |
|
|
11
|
+
|
|
12
|
+
## Table of Contents
|
|
13
|
+
|
|
14
|
+
- [@ethereumjs/common `v10`](#ethereumjscommon-v10)
|
|
15
|
+
- [Table of Contents](#table-of-contents)
|
|
16
|
+
- [Installation](#installation)
|
|
17
|
+
- [Getting Started](#getting-started)
|
|
18
|
+
- [import / require](#import--require)
|
|
19
|
+
- [Parameters](#parameters)
|
|
20
|
+
- [Custom Cryptography Primitives (WASM)](#custom-cryptography-primitives-wasm)
|
|
21
|
+
- [Example 1: keccak256 Hashing](#example-1-keccak256-hashing)
|
|
22
|
+
- [Example 2: KZG](#example-2-kzg)
|
|
23
|
+
- [Browser](#browser)
|
|
24
|
+
- [API](#api)
|
|
25
|
+
- [Docs](#docs)
|
|
26
|
+
- [Hybrid CJS/ESM Builds](#hybrid-cjsesm-builds)
|
|
27
|
+
- [Events](#events)
|
|
28
|
+
- [Chains and Genesis](#chains-and-genesis)
|
|
29
|
+
- [Working with Private/Custom Chains](#working-with-privatecustom-chains)
|
|
30
|
+
- [Initialize using Geth's genesis json](#initialize-using-geths-genesis-json)
|
|
31
|
+
- [Hardfork Support and Usage](#hardfork-support-and-usage)
|
|
32
|
+
- [Active Hardforks](#active-hardforks)
|
|
33
|
+
- [Future Hardforks](#future-hardforks)
|
|
34
|
+
- [Parameter Access](#parameter-access)
|
|
35
|
+
- [Supported EIPs](#supported-eips)
|
|
36
|
+
- [EthereumJS](#ethereumjs)
|
|
37
|
+
- [License](#license)
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
To obtain the latest version, simply require the project using `npm`:
|
|
42
|
+
|
|
43
|
+
```shell
|
|
44
|
+
npm install @ethereumjs/common
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Getting Started
|
|
48
|
+
|
|
49
|
+
### import / require
|
|
50
|
+
|
|
51
|
+
import (ESM, TypeScript):
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { Chain, Common, Hardfork } from '@ethereumjs/common'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
require (CommonJS, Node.js):
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const { Common, Chain, Hardfork } = require('@ethereumjs/common')
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Parameters
|
|
64
|
+
|
|
65
|
+
All parameters can be accessed through the `Common` class, instantiated with an object containing either the `chain` (e.g. 'Mainnet') or the `chain` together with a specific `hardfork` provided:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
// ./examples/common.ts#L1-L7
|
|
69
|
+
|
|
70
|
+
import { Common, Hardfork, Mainnet, createCustomCommon } from '@ethereumjs/common'
|
|
71
|
+
|
|
72
|
+
// With enums:
|
|
73
|
+
const commonWithEnums = new Common({ chain: Mainnet, hardfork: Hardfork.Cancun })
|
|
74
|
+
|
|
75
|
+
// Instantiate with the chain (and the default hardfork)
|
|
76
|
+
let c = new Common({ chain: Mainnet })
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
If no hardfork is provided, the common is initialized with the default hardfork.
|
|
80
|
+
|
|
81
|
+
Current `DEFAULT_HARDFORK`: `Hardfork.Prague`
|
|
82
|
+
|
|
83
|
+
Here are some simple usage examples:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// ./examples/common.ts#L9-L23
|
|
87
|
+
|
|
88
|
+
// Get bootstrap nodes for chain/network
|
|
89
|
+
console.log('Below are the known bootstrap nodes')
|
|
90
|
+
console.log(c.bootstrapNodes()) // Array with current nodes
|
|
91
|
+
|
|
92
|
+
// Instantiate with an EIP activated (with pre-EIP hardfork)
|
|
93
|
+
c = new Common({ chain: Mainnet, hardfork: Hardfork.Cancun, eips: [7702] })
|
|
94
|
+
console.log(`EIP 7702 is active -- ${c.isActivatedEIP(7702)}`)
|
|
95
|
+
|
|
96
|
+
// Instantiate common with custom chainID
|
|
97
|
+
const commonWithCustomChainId = createCustomCommon({ chainId: 1234 }, Mainnet)
|
|
98
|
+
console.log(`The current chain ID is ${commonWithCustomChainId.chainId()}`)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Custom Cryptography Primitives (WASM)
|
|
102
|
+
|
|
103
|
+
All EthereumJS packages use cryptographic primitives from the audited `ethereum-cryptography` library by default. These primitives, including `keccak256`, `sha256`, and elliptic curve signature methods, are all written in native JavaScript and therefore have the potential downside of being less performant than alternative cryptography modules written in other languages and then compiled to WASM. If cryptography performance is a bottleneck in your usage of the EthereumJS libraries, you can provide your own primitives to the `Common` constructor and they will be used in place of the defaults. Depending on how your preferred primitives are implemented, you may need to write wrapper methods around them so they conform to the interface exposed by the [`common.customCrypto` property](./src/types.ts).
|
|
104
|
+
|
|
105
|
+
Note: replacing native JS crypto primitives with WASM based libraries comes with new security assumptions (additional external dependencies, unauditability of WASM code). It is therefore recommended to evaluate your usage context before applying!
|
|
106
|
+
|
|
107
|
+
### Example 1: keccak256 Hashing
|
|
108
|
+
|
|
109
|
+
The following is an example using the [@polkadot/wasm-crypto](https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto) package:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
// ./examples/customCrypto.ts
|
|
113
|
+
|
|
114
|
+
import { createBlock } from '@ethereumjs/block'
|
|
115
|
+
import { Common, Mainnet } from '@ethereumjs/common'
|
|
116
|
+
import { keccak256, waitReady } from '@polkadot/wasm-crypto'
|
|
117
|
+
|
|
118
|
+
const main = async () => {
|
|
119
|
+
// @polkadot/wasm-crypto specific initialization
|
|
120
|
+
await waitReady()
|
|
121
|
+
|
|
122
|
+
const common = new Common({ chain: Mainnet, customCrypto: { keccak256 } })
|
|
123
|
+
const block = createBlock({}, { common })
|
|
124
|
+
|
|
125
|
+
// Method invocations within EthereumJS library instantiations where the common
|
|
126
|
+
// instance above is passed will now use the custom keccak_256 implementation
|
|
127
|
+
console.log(block.hash())
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
void main()
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Example 2: KZG
|
|
135
|
+
|
|
136
|
+
The KZG library used for EIP-4844 Blob Transactions is initialized by `common` under the `common.customCrypto` property and is then used throughout the `Ethereumjs` stack wherever KZG cryptography is required. Below is an example of how to initialize (assuming you are using the `c-kzg` package as your KZG cryptography library).
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
// ./examples/initKzg.ts
|
|
140
|
+
|
|
141
|
+
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
|
|
142
|
+
import { trustedSetup } from '@paulmillr/trusted-setups/fast-peerdas.js'
|
|
143
|
+
import { KZG as microEthKZG } from 'micro-eth-signer/kzg.js'
|
|
144
|
+
|
|
145
|
+
const main = async () => {
|
|
146
|
+
const kzg = new microEthKZG(trustedSetup)
|
|
147
|
+
const common = new Common({
|
|
148
|
+
chain: Mainnet,
|
|
149
|
+
hardfork: Hardfork.Cancun,
|
|
150
|
+
customCrypto: { kzg },
|
|
151
|
+
})
|
|
152
|
+
console.log(common.customCrypto.kzg) // Should print the initialized KZG interface
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
void main()
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Browser
|
|
159
|
+
|
|
160
|
+
We provide hybrid ESM/CJS builds for all our libraries. With the v10 breaking release round from Spring 2025 all libraries are "pure-JS" by default and we have eliminated all hard-wired WASM code. Additionally we have substantially lowered the bundle sizes, reduced the number of dependencies and cut out all usages of Node.js specific primitives (like the Node.js event emitter).
|
|
161
|
+
|
|
162
|
+
It is easily possible to run a browser build of one of the EthereumJS libraries within a modern browser using the provided ESM build. For a setup example see [./examples/browser.html](./examples/browser.html).
|
|
163
|
+
|
|
164
|
+
## API
|
|
165
|
+
|
|
166
|
+
### Docs
|
|
167
|
+
|
|
168
|
+
See the API documentation for a full list of functions for accessing specific chain and
|
|
169
|
+
dependent hardfork parameters. There are also additional helper functions like
|
|
170
|
+
`paramByBlock (topic, name, blockNumber)` or `hardforkIsActiveOnBlock (hardfork, blockNumber)`
|
|
171
|
+
to ease `blockNumber` based access to parameters.
|
|
172
|
+
|
|
173
|
+
Generated TypeDoc API [Documentation](./docs/README.md)
|
|
174
|
+
|
|
175
|
+
### Hybrid CJS/ESM Builds
|
|
176
|
+
|
|
177
|
+
With the breaking releases from Summer 2023 we have started to ship our libraries with both CommonJS (`cjs` folder) and ESM builds (`esm` folder), see `package.json` for the detailed setup.
|
|
178
|
+
|
|
179
|
+
If you use an ES6-style `import` in your code files from the ESM build will be used:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { EthereumJSClass } from '@ethereumjs/[PACKAGE_NAME]'
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
If you use Node.js specific `require`, the CJS build will be used:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
const { EthereumJSClass } = require('@ethereumjs/[PACKAGE_NAME]')
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Using ESM will give you additional advantages over CJS beyond browser usage like static code analysis / Tree Shaking which CJS can not provide.
|
|
192
|
+
|
|
193
|
+
## Events
|
|
194
|
+
|
|
195
|
+
The `Common` class has a public property `events` which contains an `EventEmitter` (using [EventEmitter3](https://github.com/primus/eventemitter3)). Following events are emitted on which you can react within your code:
|
|
196
|
+
|
|
197
|
+
| Event | Description |
|
|
198
|
+
| ----------------- | ---------------------------------------------------------- |
|
|
199
|
+
| `hardforkChanged` | Emitted when a hardfork change occurs in the Common object |
|
|
200
|
+
|
|
201
|
+
### Chains and Genesis
|
|
202
|
+
|
|
203
|
+
The `chain` can be set in the constructor like this:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
import { Common, Mainnet } from '@ethereumjs/common'
|
|
207
|
+
const common = new Common({ chain: Mainnet })
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Supported chains:
|
|
211
|
+
|
|
212
|
+
- `mainnet` (`Mainnet`)
|
|
213
|
+
- `sepolia` (`Sepolia`) (`v2.6.1`+)
|
|
214
|
+
- `holesky` (`Holesky`) (`v4.1.0`+)
|
|
215
|
+
- `hoodi` (`Hoodi`) (`v10+` (new versioning scheme))
|
|
216
|
+
- Private/custom chain parameters
|
|
217
|
+
|
|
218
|
+
The following chain-specific parameters are provided:
|
|
219
|
+
|
|
220
|
+
- `name`
|
|
221
|
+
- `chainId`
|
|
222
|
+
- `networkId`
|
|
223
|
+
- `consensusType` (e.g. `pow` or `poa`)
|
|
224
|
+
- `consensusAlgorithm` (e.g. `ethash` or `clique`)
|
|
225
|
+
- `consensusConfig` (depends on `consensusAlgorithm`, e.g. `period` and `epoch` for `clique`)
|
|
226
|
+
- `genesis` block header values
|
|
227
|
+
- `hardforks` block numbers
|
|
228
|
+
- `bootstrapNodes` list
|
|
229
|
+
- `dnsNetworks` list ([EIP-1459](https://eips.ethereum.org/EIPS/eip-1459)-compliant list of DNS networks for peer discovery)
|
|
230
|
+
|
|
231
|
+
To get an overview of the different parameters have a look at one of the chain configurations in the `chains.ts` configuration
|
|
232
|
+
file, or to the `Chain` type in [./src/types.ts](./src/types.ts).
|
|
233
|
+
|
|
234
|
+
### Working with Private/Custom Chains
|
|
235
|
+
|
|
236
|
+
Starting with the `v10` release series using custom chain configurations has been simplified and consolidated in a single API `createCustomCommon()`. This constructor can be used both to make simple chain ID adjustments and keep the rest of the config conforming to a given "base chain":
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
import { createCustomCommon, Mainnet } from '@ethereumjs/common'
|
|
240
|
+
|
|
241
|
+
createCustomCommon({chainId: 123}, Mainnet)
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
See the `Tx` library [README](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx) for how to use such a `Common` instance in the context of sending txs to L2 networks.
|
|
245
|
+
|
|
246
|
+
Beyond that, it is possible to customize to a fully custom chain by passing in a complete configuration object as first parameter:
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
// ./examples/customChain.ts
|
|
250
|
+
|
|
251
|
+
import { Mainnet, createCustomCommon } from '@ethereumjs/common'
|
|
252
|
+
import { customChainConfig } from '@ethereumjs/testdata'
|
|
253
|
+
|
|
254
|
+
// Add custom chain config
|
|
255
|
+
const common1 = createCustomCommon(customChainConfig, Mainnet)
|
|
256
|
+
console.log(`Common is instantiated with custom chain parameters - ${common1.chainName()}`)
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
#### Initialize using Geth's genesis json
|
|
261
|
+
|
|
262
|
+
For lots of custom chains (e.g., devnets and testnets), you might come across a genesis json config which
|
|
263
|
+
has both config specification for the chain as well as the genesis state specification. You can derive the
|
|
264
|
+
common from such configuration in the following manner:
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
// ./examples/fromGeth.ts
|
|
268
|
+
|
|
269
|
+
import { createCommonFromGethGenesis } from '@ethereumjs/common'
|
|
270
|
+
import { postMergeGethGenesis } from '@ethereumjs/testdata'
|
|
271
|
+
import { hexToBytes } from '@ethereumjs/util'
|
|
272
|
+
|
|
273
|
+
const genesisHash = hexToBytes('0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a')
|
|
274
|
+
// Load geth genesis JSON file into lets say `genesisJSON` and optional `chain` and `genesisHash`
|
|
275
|
+
const common = createCommonFromGethGenesis(postMergeGethGenesis, {
|
|
276
|
+
chain: 'customChain',
|
|
277
|
+
genesisHash,
|
|
278
|
+
})
|
|
279
|
+
// If you don't have `genesisHash` while initiating common, you can later configure common (for e.g.
|
|
280
|
+
// after calculating it via `blockchain`)
|
|
281
|
+
common.setForkHashes(genesisHash)
|
|
282
|
+
|
|
283
|
+
console.log(`The London forkhash for this custom chain is ${common.forkHash('london')}`)
|
|
284
|
+
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## Hardfork Support and Usage
|
|
288
|
+
|
|
289
|
+
The `hardfork` can be set in constructor like this:
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
// ./examples/common.ts#L1-L4
|
|
293
|
+
|
|
294
|
+
import { Common, Hardfork, Mainnet, createCustomCommon } from '@ethereumjs/common'
|
|
295
|
+
|
|
296
|
+
// With enums:
|
|
297
|
+
const commonWithEnums = new Common({ chain: Mainnet, hardfork: Hardfork.Cancun })
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Active Hardforks
|
|
301
|
+
|
|
302
|
+
There are currently parameter changes by the following past and future hardforks
|
|
303
|
+
supported by the library:
|
|
304
|
+
|
|
305
|
+
- `chainstart` (`Hardfork.Chainstart`)
|
|
306
|
+
- `homestead` (`Hardfork.Homestead`)
|
|
307
|
+
- `dao` (`Hardfork.Dao`)
|
|
308
|
+
- `tangerineWhistle` (`Hardfork.TangerineWhistle`)
|
|
309
|
+
- `spuriousDragon` (`Hardfork.SpuriousDragon`)
|
|
310
|
+
- `byzantium` (`Hardfork.Byzantium`)
|
|
311
|
+
- `constantinople` (`Hardfork.Constantinople`)
|
|
312
|
+
- `petersburg` (`Hardfork.Petersburg`) (aka `constantinopleFix`, apply together with `constantinople`)
|
|
313
|
+
- `istanbul` (`Hardfork.Istanbul`)
|
|
314
|
+
- `muirGlacier` (`Hardfork.MuirGlacier`)
|
|
315
|
+
- `berlin` (`Hardfork.Berlin`) (since `v2.2.0`)
|
|
316
|
+
- `london` (`Hardfork.London`) (since `v2.4.0`)
|
|
317
|
+
- `merge` (`Hardfork.Merge`) (since `v2.5.0`)
|
|
318
|
+
- `shanghai` (`Hardfork.Shanghai`) (since `v3.1.0`)
|
|
319
|
+
- `cancun` (`Hardfork.Cancun`) (since `v4.2.0`)
|
|
320
|
+
- `prague` (`Hardfork.Prague`) (`DEFAULT_HARDFORK`) (since `v10`)
|
|
321
|
+
- `osaka` (`Hardfork.Osaka`) (since `v10.1.0`)
|
|
322
|
+
- `amsterdam` (`Hardfork.Amsterdam`) (IN DEVELOPMENT)
|
|
323
|
+
|
|
324
|
+
### Future Hardforks
|
|
325
|
+
|
|
326
|
+
The next upcoming HF `Hardfork.Amsterdam` is currently in development (started January 2026).
|
|
327
|
+
|
|
328
|
+
### Parameter Access
|
|
329
|
+
|
|
330
|
+
For hardfork-specific parameter access with the `param()` and `paramByBlock()` functions
|
|
331
|
+
you can use the following `topics`:
|
|
332
|
+
|
|
333
|
+
- `gasConfig`
|
|
334
|
+
- `gasPrices`
|
|
335
|
+
- `vm`
|
|
336
|
+
- `pow`
|
|
337
|
+
- `sharding`
|
|
338
|
+
|
|
339
|
+
See one of the hardfork configurations in the `hardforks.ts` file
|
|
340
|
+
for an overview. For consistency, the chain start (`chainstart`) is considered an own
|
|
341
|
+
hardfork.
|
|
342
|
+
|
|
343
|
+
## Supported EIPs
|
|
344
|
+
|
|
345
|
+
EIPs are native citizens within the library and can be activated like this:
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Cancun, eips: [7702] })
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
The following EIPs are currently supported:
|
|
352
|
+
|
|
353
|
+
- [EIP-1153](https://eips.ethereum.org/EIPS/eip-1153) - Transient storage opcodes (Cancun)
|
|
354
|
+
- [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) - Fee market change for ETH 1.0 chain
|
|
355
|
+
- [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537) - Precompile for BLS12-381 curve operations (Prague)
|
|
356
|
+
- [EIP-2565](https://eips.ethereum.org/EIPS/eip-2565) - ModExp gas cost
|
|
357
|
+
- [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718) - Transaction Types
|
|
358
|
+
- [EIP-2935](https://eips.ethereum.org/EIPS/eip-2935) - Serve historical block hashes in state (Prague)
|
|
359
|
+
- [EIP-2929](https://eips.ethereum.org/EIPS/eip-2929) - gas cost increases for state access opcodes
|
|
360
|
+
- [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930) - Optional access list tx type
|
|
361
|
+
- [EIP-3074](https://eips.ethereum.org/EIPS/eip-3074) - AUTH and AUTHCALL opcodes
|
|
362
|
+
- [EIP-3198](https://eips.ethereum.org/EIPS/eip-3198) - Base fee Opcode
|
|
363
|
+
- [EIP-3529](https://eips.ethereum.org/EIPS/eip-3529) - Reduction in refunds
|
|
364
|
+
- [EIP-3541](https://eips.ethereum.org/EIPS/eip-3541) - Reject new contracts starting with the 0xEF byte
|
|
365
|
+
- [EIP-3554](https://eips.ethereum.org/EIPS/eip-3554) - Difficulty Bomb Delay to December 2021 (only PoW networks)
|
|
366
|
+
- [EIP-3607](https://eips.ethereum.org/EIPS/eip-3607) - Reject transactions from senders with deployed code
|
|
367
|
+
- [EIP-3651](https://eips.ethereum.org/EIPS/eip-3651) - Warm COINBASE (Shanghai)
|
|
368
|
+
- [EIP-3675](https://eips.ethereum.org/EIPS/eip-3675) - Upgrade consensus to Proof-of-Stake
|
|
369
|
+
- [EIP-3855](https://eips.ethereum.org/EIPS/eip-3855) - Push0 opcode (Shanghai)
|
|
370
|
+
- [EIP-3860](https://eips.ethereum.org/EIPS/eip-3860) - Limit and meter initcode (Shanghai)
|
|
371
|
+
- [EIP-4345](https://eips.ethereum.org/EIPS/eip-4345) - Difficulty Bomb Delay to June 2022
|
|
372
|
+
- [EIP-4399](https://eips.ethereum.org/EIPS/eip-4399) - Supplant DIFFICULTY opcode with PREVRANDAO (Merge)
|
|
373
|
+
- [EIP-4788](https://eips.ethereum.org/EIPS/eip-4788) - Beacon block root in the EVM (Cancun)
|
|
374
|
+
- [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) - Shard Blob Transactions (Cancun)
|
|
375
|
+
- [EIP-4895](https://eips.ethereum.org/EIPS/eip-4895) - Beacon chain push withdrawals as operations (Shanghai)
|
|
376
|
+
- [EIP-5133](https://eips.ethereum.org/EIPS/eip-5133) - Delaying Difficulty Bomb to mid-September 2022 (Gray Glacier)
|
|
377
|
+
- [EIP-5656](https://eips.ethereum.org/EIPS/eip-5656) - MCOPY - Memory copying instruction (Cancun)
|
|
378
|
+
- [EIP-6110](https://eips.ethereum.org/EIPS/eip-6110) - Supply validator deposits on chain (Prague)
|
|
379
|
+
- [EIP-6780](https://eips.ethereum.org/EIPS/eip-6780) - SELFDESTRUCT only in same transaction (Cancun)
|
|
380
|
+
- [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002) - Execution layer triggerable exits (Prague)
|
|
381
|
+
- [EIP-7251](https://eips.ethereum.org/EIPS/eip-7251) - Increase the MAX_EFFECTIVE_BALANCE (Prague)
|
|
382
|
+
- [EIP-7516](https://eips.ethereum.org/EIPS/eip-7516) - BLOBBASEFEE opcode (Cancun)
|
|
383
|
+
- [EIP-7623](https://eips.ethereum.org/EIPS/eip-7623) - Increase calldata cost (Prague)
|
|
384
|
+
- [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685) - General purpose execution layer requests (Prague)
|
|
385
|
+
- [EIP-7691](https://eips.ethereum.org/EIPS/eip-7691) - Blob throughput increase (Prague)
|
|
386
|
+
- [EIP-7692](https://eips.ethereum.org/EIPS/eip-7692) - EVM Object Format (EOF) v1 (`experimental`)
|
|
387
|
+
- [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) - Set EOA account code (Prague)
|
|
388
|
+
- [EIP-7709](https://eips.ethereum.org/EIPS/eip-7709) - Read BLOCKHASH from storage and update cost (Verkle)
|
|
389
|
+
- [EIP-7918](https://eips.ethereum.org/EIPS/eip-7918) - Blob base fee bounded by execution cost (Osaka)
|
|
390
|
+
- [EIP-7928](https://eips.ethereum.org/EIPS/eip-7928) - Block Level Access Lists (Amsterdam) (IN DEVELOPMENT)
|
|
391
|
+
|
|
392
|
+
## EthereumJS
|
|
393
|
+
|
|
394
|
+
The `EthereumJS` GitHub organization and its repositories are managed by members of the former Ethereum Foundation JavaScript team and the broader Ethereum community. If you want to join for work or carry out improvements on the libraries see the [developer docs](../../DEVELOPER.md) for an overview of current standards and tools and review our [code of conduct](../../CODE_OF_CONDUCT.md).
|
|
395
|
+
|
|
396
|
+
## License
|
|
397
|
+
|
|
398
|
+
[MIT](https://opensource.org/licenses/MIT)
|
|
399
|
+
|
|
400
|
+
[discord-badge]: https://img.shields.io/static/v1?logo=discord&label=discord&message=Join&color=blue
|
|
401
|
+
[discord-link]: https://discord.gg/TNwARpR
|
|
402
|
+
[common-npm-badge]: https://img.shields.io/npm/v/@ethereumjs/common.svg
|
|
403
|
+
[common-npm-link]: https://www.npmjs.com/package/@ethereumjs/common
|
|
404
|
+
[common-issues-badge]: https://img.shields.io/github/issues/ethereumjs/ethereumjs-monorepo/package:%20common?label=issues
|
|
405
|
+
[common-issues-link]: https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aopen+is%3Aissue+label%3A"package%3A+common"
|
|
406
|
+
[common-actions-badge]: https://github.com/ethereumjs/ethereumjs-monorepo/workflows/Common/badge.svg
|
|
407
|
+
[common-actions-link]: https://github.com/ethereumjs/ethereumjs-monorepo/actions?query=workflow%3A%22Common%22
|
|
408
|
+
[common-coverage-badge]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/branch/master/graph/badge.svg?flag=common
|
|
409
|
+
[common-coverage-link]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/tree/master/packages/common
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../src/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,eAAO,MAAM,OAAO,EAAE,WA+KrB,CAAA;AAED,eAAO,MAAM,OAAO,EAAE,WAiKrB,CAAA;AAED,eAAO,MAAM,OAAO,EAAE,WA6IrB,CAAA;AAED,eAAO,MAAM,KAAK,EAAE,WAwJnB,CAAA"}
|