-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeGenesis.js
56 lines (48 loc) · 1.77 KB
/
makeGenesis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const fs = require('fs');
// Function to create genesis file
function createGenesis(chainId, sealerAddress, allocAddress) {
const extraData = `0x0000000000000000000000000000000000000000000000000000000000000000${sealerAddress}0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000`;
const genesis = {
"config": {
"chainId": parseInt(chainId),
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"clique": {
"period": 6
}
},
"difficulty": "1",
"gasLimit": "8000000",
"extraData": extraData,
"nonce": "0x0",
"alloc": {}
};
genesis.alloc[allocAddress] = {
"balance": "1000001000000000000000000"
};
return genesis;
}
// Parsing command line arguments
const chainId = process.argv[2];
const sealerAddress = process.argv[3].replace("0x", "");
const allocAddress = process.argv[4] ? process.argv[4] : process.argv[3];
const outputPath = process.argv[5];
// Validate outputPath
if (!outputPath) {
console.error("Output path for genesis file is required.");
process.exit(1);
}
// Create genesis file
const genesis = createGenesis(chainId, sealerAddress, allocAddress);
// Write genesis to the specified file
fs.writeFileSync(outputPath, JSON.stringify(genesis, null, 2));
console.log(`Genesis file created at ${outputPath}`);