Repository navigation
Expand file tree
/
Copy pathhardhat.helpers.ts
More file actions
55 lines (43 loc) · 1.41 KB
/
Copy pathhardhat.helpers.ts
File metadata and controls
55 lines (43 loc) · 1.41 KB
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
import { existsSync, readFileSync } from "node:fs";
import { HardhatNetworkForkingUserConfig } from "hardhat/types";
export function getMode() {
return process.env.MODE || "scratch";
}
/* Determines the forking configuration for Hardhat */
export function getHardhatForkingConfig() {
const mode = getMode();
if (mode === "scratch") {
process.env.INTEGRATION_WITH_CSM = "off";
return undefined;
}
if (mode === "forking") {
const url = process.env.RPC_URL || "";
if (!url) {
throw new Error("RPC_URL must be set when MODE=forking");
}
const config: HardhatNetworkForkingUserConfig = { url };
const block = process.env.FORKING_BLOCK_NUMBER;
if (block) {
const blockNumber = Number(block);
if (!blockNumber || blockNumber <= 0) {
throw new Error(`Invalid FORKING_BLOCK_NUMBER: ${block}`);
}
config.blockNumber = blockNumber;
}
return config;
}
throw new Error("MODE must be either 'scratch' or 'forking'");
}
// TODO: this plaintext accounts.json private keys management is a subject
// of rework to a solution with the keys stored encrypted
export function loadAccounts(networkName: string) {
const accountsPath = "./accounts.json";
if (!existsSync(accountsPath)) {
return [];
}
const content = JSON.parse(readFileSync(accountsPath, "utf-8"));
if (!content.eth) {
return [];
}
return content.eth[networkName] || [];
}