-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathhardhat.helpers.ts
38 lines (30 loc) · 1 KB
/
hardhat.helpers.ts
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
import { existsSync, readFileSync } from "node:fs";
/* Determines the forking configuration for Hardhat */
export function getHardhatForkingConfig() {
const mode = process.env.MODE || "scratch";
switch (mode) {
case "scratch":
process.env.INTEGRATION_WITH_CSM = "off";
return undefined;
case "forking":
if (!process.env.FORK_RPC_URL) {
throw new Error("FORK_RPC_URL must be set when MODE=forking");
}
return { url: process.env.FORK_RPC_URL };
default:
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] || [];
}