|
@@ -2,8 +2,8 @@ import { config as dotenvConfig } from "dotenv";
|
|
|
import { resolve } from "path";
|
|
|
dotenvConfig({ path: resolve(__dirname, "./.env") });
|
|
|
|
|
|
-import { HardhatNetworkAccountsUserConfig } from "hardhat/types";
|
|
|
import { HardhatUserConfig } from "hardhat/config";
|
|
|
+import { NetworkUserConfig } from "hardhat/types";
|
|
|
import "./tasks/accounts";
|
|
|
import "./tasks/clean";
|
|
|
|
|
@@ -11,61 +11,59 @@ import "@nomiclabs/hardhat-waffle";
|
|
|
import "hardhat-typechain";
|
|
|
import "solidity-coverage";
|
|
|
|
|
|
-/**
|
|
|
- * @dev You must have a `.env` file. Follow the example in `.env.example`.
|
|
|
- * @param {string} network The name of the testnet
|
|
|
- */
|
|
|
-function createNetworkConfig(
|
|
|
- network?: string,
|
|
|
-): { accounts: HardhatNetworkAccountsUserConfig; url: string | undefined } {
|
|
|
- if (!process.env.MNEMONIC) {
|
|
|
- throw new Error("Please set your MNEMONIC in a .env file");
|
|
|
- }
|
|
|
+const chainIds = {
|
|
|
+ ganache: 1337,
|
|
|
+ goerli: 5,
|
|
|
+ hardhat: 31337,
|
|
|
+ kovan: 42,
|
|
|
+ mainnet: 1,
|
|
|
+ rinkeby: 4,
|
|
|
+ ropsten: 3,
|
|
|
+};
|
|
|
|
|
|
- if (!process.env.INFURA_API_KEY) {
|
|
|
- throw new Error("Please set your INFURA_API_KEY");
|
|
|
- }
|
|
|
+// Ensure that we have all the environment variables we need.
|
|
|
+let mnemonic: string;
|
|
|
+if (!process.env.MNEMONIC) {
|
|
|
+ throw new Error("Please set your MNEMONIC in a .env file");
|
|
|
+} else {
|
|
|
+ mnemonic = process.env.MNEMONIC;
|
|
|
+}
|
|
|
|
|
|
+let infuraApiKey: string;
|
|
|
+if (!process.env.INFURA_API_KEY) {
|
|
|
+ throw new Error("Please set your INFURA_API_KEY in a .env file");
|
|
|
+} else {
|
|
|
+ infuraApiKey = process.env.INFURA_API_KEY;
|
|
|
+}
|
|
|
+
|
|
|
+function createTestnetConfig(network: keyof typeof chainIds): NetworkUserConfig {
|
|
|
+ const url: string = "https://" + network + ".infura.io/v3/" + infuraApiKey;
|
|
|
return {
|
|
|
accounts: {
|
|
|
count: 10,
|
|
|
initialIndex: 0,
|
|
|
- mnemonic: process.env.MNEMONIC,
|
|
|
+ mnemonic,
|
|
|
path: "m/44'/60'/0'/0",
|
|
|
},
|
|
|
- url: network ? `https://${network}.infura.io/v3/${process.env.INFURA_API_KEY}` : undefined,
|
|
|
+ chainId: chainIds[network],
|
|
|
+ url,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
const config: HardhatUserConfig = {
|
|
|
defaultNetwork: "hardhat",
|
|
|
mocha: {
|
|
|
- /* Without this property set, the "setTimeout" from the Greeter.js file wouldn't work. */
|
|
|
+ // Without this property set, the "setTimeout" from the Greeter.js file wouldn't work.
|
|
|
delay: true,
|
|
|
},
|
|
|
networks: {
|
|
|
hardhat: {
|
|
|
- chainId: 31337,
|
|
|
- },
|
|
|
- coverage: {
|
|
|
- url: "http://127.0.0.1:8555",
|
|
|
- },
|
|
|
- goerli: {
|
|
|
- ...createNetworkConfig("goerli"),
|
|
|
- chainId: 5,
|
|
|
- },
|
|
|
- kovan: {
|
|
|
- ...createNetworkConfig("kovan"),
|
|
|
- chainId: 42,
|
|
|
- },
|
|
|
- rinkeby: {
|
|
|
- ...createNetworkConfig("rinkeby"),
|
|
|
- chainId: 4,
|
|
|
- },
|
|
|
- ropsten: {
|
|
|
- ...createNetworkConfig("ropsten"),
|
|
|
- chainId: 3,
|
|
|
+ chainId: chainIds.hardhat,
|
|
|
},
|
|
|
+ goerli: createTestnetConfig("goerli"),
|
|
|
+ kovan: createTestnetConfig("kovan"),
|
|
|
+ rinkeby: createTestnetConfig("rinkeby"),
|
|
|
+ ropsten: createTestnetConfig("ropsten"),
|
|
|
},
|
|
|
paths: {
|
|
|
artifacts: "./artifacts",
|
|
@@ -77,8 +75,8 @@ const config: HardhatUserConfig = {
|
|
|
},
|
|
|
solidity: {
|
|
|
version: "0.7.4",
|
|
|
- /* https://hardhat.org/hardhat-network/#solidity-optimizer-support */
|
|
|
settings: {
|
|
|
+ // https://hardhat.org/hardhat-network/#solidity-optimizer-support
|
|
|
optimizer: {
|
|
|
enabled: true,
|
|
|
runs: 200,
|