-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathhardhat.config.ts
More file actions
106 lines (90 loc) · 2.9 KB
/
hardhat.config.ts
File metadata and controls
106 lines (90 loc) · 2.9 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
/// <reference types="node" />
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import dotenv from "dotenv";
dotenv.config();
// ⚠️ SECURITY WARNING ⚠️
// NEVER hardcode private keys in this file.
// Always use environment variables from a .env file.
// Ensure .env is added to .gitignore
// For production, use hardware wallets or secret management services.
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL || "";
const SEPOLIA_PRIVATE_KEY = process.env.SEPOLIA_PRIVATE_KEY || "";
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || "";
if (!ETHERSCAN_API_KEY && process.env.NODE_ENV !== "test") {
console.warn(
"⚠️ ETHERSCAN_API_KEY is not set — contract verification will fail on Sepolia."
);
}
if (!SEPOLIA_RPC_URL && process.env.NODE_ENV === "production") {
console.warn("⚠️ SEPOLIA_RPC_URL is not set in .env");
}
if (!SEPOLIA_PRIVATE_KEY && process.env.NODE_ENV === "production") {
console.warn(
"⚠️ SEPOLIA_PRIVATE_KEY is not set in .env - cannot deploy to Sepolia"
);
}
const config: HardhatUserConfig = {
solidity: {
version: "0.8.20",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
networks: {
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: SEPOLIA_PRIVATE_KEY ? [SEPOLIA_PRIVATE_KEY] : [],
chainId: 11155111,
// Gas settings for Sepolia (adjust as needed)
gasPrice: "auto",
},
// Local hardhat network for development
hardhat: {
chainId: 31337,
},
// Optional: localhost network for running local node
localhost: {
url: "http://127.0.0.1:8545",
},
},
// ─── Block-explorer verification ─────────────────────────────────────────
// @nomicfoundation/hardhat-verify resolves apiKey by network name.
// Add entries here when targeting additional chains (e.g. mainnet, polygon).
etherscan: {
apiKey: {
sepolia: ETHERSCAN_API_KEY,
mainnet: ETHERSCAN_API_KEY,
},
// Extend with custom chains that are not natively supported by hardhat-verify
customChains: [],
},
// Sourcify: decentralised, IPFS-backed verification (no API key required).
// Falls back to this if Etherscan verification is unavailable.
sourcify: {
enabled: true,
},
// Gas reporter
gasReporter: {
enabled: process.env.REPORT_GAS === "true",
currency: "USD",
coinmarketcap: process.env.COINMARKETCAP_API_KEY || "",
outputFile: "gas-report.txt",
noColors: true,
},
// Paths
paths: {
sources: "./contracts",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts",
},
// Mocha test timeout
mocha: {
timeout: 40000,
},
};
export default config;