-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhardhat.config.js
More file actions
119 lines (111 loc) · 3.04 KB
/
hardhat.config.js
File metadata and controls
119 lines (111 loc) · 3.04 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import '@nomicfoundation/hardhat-toolbox';
import 'dotenv/config';
const {
MAINNET_RPC_URL,
SEPOLIA_RPC_URL,
PRIVATE_KEY,
ETHERSCAN_API_KEY,
BASESCAN_API_KEY,
ARBISCAN_API_KEY,
// Frontend RPC fallbacks so you don't need to duplicate env vars
VITE_ETH_RPC_URL,
VITE_RPC_URL,
} = process.env;
// Resolve RPC URLs with sane fallbacks.
// Note: If you use VITE_* URLs, ensure they actually point to the intended network.
const resolvedMainnetUrl =
MAINNET_RPC_URL || VITE_ETH_RPC_URL || VITE_RPC_URL || 'https://mainnet.infura.io/v3/YOUR_INFURA_KEY';
const resolvedSepoliaUrl =
SEPOLIA_RPC_URL || VITE_ETH_RPC_URL || VITE_RPC_URL || 'https://sepolia.infura.io/v3/YOUR_INFURA_KEY';
// Diagnostics (masked) to help catch placeholder or malformed RPC values
const maskUrl = (u) => {
if (!u) return String(u);
try {
const shown = u.slice(0, 24);
const tail = u.slice(-6);
return `${shown}…${tail}`;
} catch {
return '***';
}
};
const warnUrl = (name, u) => {
if (!u) {
console.warn(`[hardhat] ${name} RPC URL is empty or undefined`);
return;
}
if (u.includes('YOUR_INFURA_KEY')) {
console.error(`[hardhat] ${name} RPC URL contains placeholder "YOUR_INFURA_KEY" — set a real project id`);
}
if (/^wss:/i.test(u)) {
console.error(`[hardhat] ${name} RPC URL uses WSS; Hardhat HTTP provider requires HTTPS URL`);
}
if (/["']/.test(u)) {
console.error(
`[hardhat] ${name} RPC URL appears to include quotes — remove quotes in .env (e.g., MAINNET_RPC_URL=https://...)`
);
}
};
// Always print masked endpoints so we can verify which variable Hardhat resolved
console.log(`[hardhat] mainnet RPC -> ${maskUrl(resolvedMainnetUrl)}`);
console.log(`[hardhat] sepolia RPC -> ${maskUrl(resolvedSepoliaUrl)}`);
warnUrl('mainnet', resolvedMainnetUrl);
warnUrl('sepolia', resolvedSepoliaUrl);
const config = {
solidity: {
version: '0.8.24',
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
networks: {
hardhat: {
chainId: 31337,
},
localhost: {
url: 'http://127.0.0.1:8545',
chainId: 31337,
},
sepolia: {
url: resolvedSepoliaUrl,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
chainId: 11155111,
},
mainnet: {
url: resolvedMainnetUrl,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
chainId: 1,
},
base: {
url: 'https://mainnet.base.org',
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
chainId: 8453,
},
arbitrum: {
url: 'https://arb1.arbitrum.io/rpc',
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
chainId: 42161,
},
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
currency: 'USD',
},
etherscan: {
apiKey: {
mainnet: ETHERSCAN_API_KEY,
sepolia: ETHERSCAN_API_KEY,
base: BASESCAN_API_KEY,
arbitrumOne: ARBISCAN_API_KEY,
},
},
paths: {
sources: './contracts',
tests: './test/contracts',
cache: './cache',
artifacts: './artifacts',
},
};
export default config;