This repository has been archived by the owner on Oct 31, 2021. It is now read-only.
generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 11
/
hardhat.config.ts
98 lines (86 loc) · 2.38 KB
/
hardhat.config.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
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
import "@nomiclabs/hardhat-waffle";
import "hardhat-abi-exporter";
import "@nomiclabs/hardhat-etherscan";
import "@typechain/hardhat";
import { HardhatUserConfig } from "hardhat/config";
import { NetworkUserConfig } from "hardhat/types";
import dotenv from "dotenv";
dotenv.config();
const chainIds = {
ganache: 1337,
goerli: 5,
hardhat: 31337,
kovan: 42,
mainnet: 1,
rinkeby: 4,
ropsten: 3,
polygon: 137,
mumbai: 80001,
};
// Ensure that we have all the environment variables we need.
let testPrivateKey: string = process.env.TEST_PRIVATE_KEY || "";
let alchemyKey: string = process.env.ALCHEMY_KEY || "";
let etherscanKey: string = process.env.ETHERSCAN_API_KEY || "";
let polygonscanKey: string = process.env.POLYGONSCAN_API_KEY || "";
function createTestnetConfig(network: keyof typeof chainIds): NetworkUserConfig {
if (!alchemyKey) {
throw new Error("Missing ALCHEMY_KEY");
}
const polygonNetworkName = network === "polygon" ? "mainnet" : "mumbai";
let nodeUrl =
chainIds[network] == 137 || chainIds[network] == 80001
? `https://polygon-${polygonNetworkName}.g.alchemy.com/v2/${alchemyKey}`
: `https://eth-${network}.alchemyapi.io/v2/${alchemyKey}`;
return {
chainId: chainIds[network],
url: nodeUrl,
accounts: [`${testPrivateKey}`],
};
}
interface ConfigWithEtherscan extends HardhatUserConfig {
etherscan: { apiKey: string };
}
const config: ConfigWithEtherscan = {
paths: {
artifacts: "./artifacts",
cache: "./cache",
sources: "./contracts",
tests: "./test",
},
solidity: {
version: "0.8.0",
settings: {
metadata: {
// Not including the metadata hash
// https://github.com/paulrberg/solidity-template/issues/31
bytecodeHash: "none",
},
// You should disable the optimizer when debugging
// https://hardhat.org/hardhat-network/#solidity-optimizer-support
optimizer: {
enabled: true,
runs: 800,
},
},
},
abiExporter: {
flat: true,
},
typechain: {
outDir: "typechain",
target: "ethers-v5",
},
etherscan: {
// apiKey: etherscanKey,
apiKey: polygonscanKey,
},
};
if (testPrivateKey) {
config.networks = {
mainnet: createTestnetConfig("mainnet"),
rinkeby: createTestnetConfig("rinkeby"),
polygon: createTestnetConfig("polygon"),
mumbai: createTestnetConfig("mumbai"),
};
}
export default config;