-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into update-vitest
- Loading branch information
Showing
15 changed files
with
447 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"config": { | ||
"chainId": 1, | ||
"homesteadBlock": 0, | ||
"eip150Block": 0, | ||
"eip155Block": 0, | ||
"eip158Block": 0, | ||
"byzantiumBlock": 0, | ||
"constantinopleBlock": 0, | ||
"petersburgBlock": 0, | ||
"istanbulBlock": 0, | ||
"muirGlacierBlock": 0, | ||
"berlinBlock": 0, | ||
"londonBlock": 0, | ||
"clique": { | ||
"period": 5, | ||
"epoch": 30000 | ||
}, | ||
"terminalTotalDifficulty": 0 | ||
}, | ||
"nonce": "0x42", | ||
"timestamp": "0x0", | ||
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | ||
"gasLimit": "0x1C9C380", | ||
"difficulty": "0x400000000", | ||
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"coinbase": "0x0000000000000000000000000000000000000000", | ||
"alloc": { | ||
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { "balance": "0x6d6172697573766477000000" } | ||
}, | ||
"number": "0x0", | ||
"gasUsed": "0x0", | ||
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"baseFeePerGas": "0x7" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Blockchain } from '@ethereumjs/blockchain' | ||
import { Common, parseGethGenesis } from '@ethereumjs/common' | ||
import { bytesToHex, parseGethGenesisState } from '@ethereumjs/util' | ||
import gethGenesisJson from './genesisData/post-merge.json' | ||
|
||
const main = async () => { | ||
// Load geth genesis json file into lets say `gethGenesisJson` | ||
const common = Common.fromGethGenesis(gethGenesisJson, { chain: 'customChain' }) | ||
const genesisState = parseGethGenesisState(gethGenesisJson) | ||
const blockchain = await Blockchain.create({ | ||
genesisState, | ||
common, | ||
}) | ||
const genesisBlockHash = blockchain.genesisBlock.hash() | ||
common.setForkHashes(genesisBlockHash) | ||
console.log( | ||
`Genesis hash from geth genesis parameters - ${bytesToHex(blockchain.genesisBlock.hash())}` | ||
) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Block } from '@ethereumjs/block' | ||
import { Blockchain } from '@ethereumjs/blockchain' | ||
import { Common, Hardfork } from '@ethereumjs/common' | ||
import { bytesToHex } from '@ethereumjs/util' | ||
|
||
const main = async () => { | ||
const common = new Common({ chain: 'mainnet', hardfork: Hardfork.London }) | ||
// Use the safe static constructor which awaits the init method | ||
const blockchain = await Blockchain.create({ | ||
validateBlocks: false, // Skipping validation so we can make a simple chain without having to provide complete blocks | ||
validateConsensus: false, | ||
common, | ||
}) | ||
|
||
// We use minimal data to provide a sequence of blocks (increasing number, difficulty, and then setting parent hash to previous block) | ||
const block = Block.fromBlockData( | ||
{ | ||
header: { | ||
number: 1n, | ||
parentHash: blockchain.genesisBlock.hash(), | ||
difficulty: blockchain.genesisBlock.header.difficulty + 1n, | ||
}, | ||
}, | ||
{ common, setHardfork: true } | ||
) | ||
const block2 = Block.fromBlockData( | ||
{ | ||
header: { | ||
number: 2n, | ||
parentHash: block.header.hash(), | ||
difficulty: block.header.difficulty + 1n, | ||
}, | ||
}, | ||
{ common, setHardfork: true } | ||
) | ||
// See @ethereumjs/block for more details on how to create a block | ||
await blockchain.putBlock(block) | ||
await blockchain.putBlock(block2) | ||
|
||
// We iterate over the blocks in the chain to the current head (block 2) | ||
await blockchain.iterator('i', (block) => { | ||
const blockNumber = block.header.number.toString() | ||
const blockHash = bytesToHex(block.hash()) | ||
console.log(`Block ${blockNumber}: ${blockHash}`) | ||
}) | ||
|
||
// Block 1: 0xa1a061528d74ba81f560e1ebc4f29d6b58171fc13b72b876cdffe6e43b01bdc5 | ||
// Block 2: 0x5583be91cf9fb14f5dbeb03ad56e8cef19d1728f267c35a25ba5a355a528f602 | ||
} | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Chain, Common, Hardfork } from '@ethereumjs/common' | ||
|
||
// With enums: | ||
const commonWithEnums = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) | ||
|
||
// (also possible with directly passing in strings:) | ||
const commonWithStrings = new Common({ chain: 'mainnet', hardfork: 'london' }) | ||
|
||
// Instantiate with the chain (and the default hardfork) | ||
let c = new Common({ chain: Chain.Mainnet }) | ||
console.log(`The gas price for ecAdd is ${c.param('gasPrices', 'ecAddGas')}`) // 500 | ||
|
||
// Chain and hardfork provided | ||
c = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Byzantium }) | ||
console.log(`The miner reward under PoW on Byzantium us ${c.param('pow', 'minerReward')}`) // 3000000000000000000 | ||
|
||
// Get bootstrap nodes for chain/network | ||
console.log('Below are the known bootstrap nodes') | ||
console.log(c.bootstrapNodes()) // Array with current nodes | ||
|
||
// Instantiate with an EIP activated | ||
c = new Common({ chain: Chain.Mainnet, eips: [4844] }) | ||
console.log(`EIP 4844 is active -- ${c.isActivatedEIP(4844)}`) | ||
|
||
// Instantiate common with custom chainID | ||
const commonWithCustomChainId = Common.custom({ chainId: 1234 }) | ||
console.log(`The current chain ID is ${commonWithCustomChainId.chainId}`) |
Oops, something went wrong.