hardhat.config.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { config as dotenvConfig } from "dotenv";
  2. import { resolve } from "path";
  3. dotenvConfig({ path: resolve(__dirname, "./.env") });
  4. import { HardhatUserConfig } from "hardhat/config";
  5. import { NetworkUserConfig } from "hardhat/types";
  6. import "./tasks/accounts";
  7. import "./tasks/clean";
  8. import "@nomiclabs/hardhat-waffle";
  9. import "hardhat-typechain";
  10. import "solidity-coverage";
  11. const chainIds = {
  12. ganache: 1337,
  13. goerli: 5,
  14. hardhat: 31337,
  15. kovan: 42,
  16. mainnet: 1,
  17. rinkeby: 4,
  18. ropsten: 3,
  19. };
  20. // Ensure that we have all the environment variables we need.
  21. let mnemonic: string;
  22. if (!process.env.MNEMONIC) {
  23. throw new Error("Please set your MNEMONIC in a .env file");
  24. } else {
  25. mnemonic = process.env.MNEMONIC;
  26. }
  27. let infuraApiKey: string;
  28. if (!process.env.INFURA_API_KEY) {
  29. throw new Error("Please set your INFURA_API_KEY in a .env file");
  30. } else {
  31. infuraApiKey = process.env.INFURA_API_KEY;
  32. }
  33. function createTestnetConfig(network: keyof typeof chainIds): NetworkUserConfig {
  34. const url: string = "https://" + network + ".infura.io/v3/" + infuraApiKey;
  35. return {
  36. accounts: {
  37. count: 10,
  38. initialIndex: 0,
  39. mnemonic,
  40. path: "m/44'/60'/0'/0",
  41. },
  42. chainId: chainIds[network],
  43. url,
  44. };
  45. }
  46. const config: HardhatUserConfig = {
  47. defaultNetwork: "hardhat",
  48. networks: {
  49. hardhat: {
  50. chainId: chainIds.hardhat,
  51. },
  52. goerli: createTestnetConfig("goerli"),
  53. kovan: createTestnetConfig("kovan"),
  54. rinkeby: createTestnetConfig("rinkeby"),
  55. ropsten: createTestnetConfig("ropsten"),
  56. },
  57. paths: {
  58. artifacts: "./artifacts",
  59. cache: "./cache",
  60. coverage: "./coverage",
  61. coverageJson: "./coverage.json",
  62. sources: "./contracts",
  63. tests: "./test",
  64. },
  65. solidity: {
  66. version: "0.7.4",
  67. settings: {
  68. // https://hardhat.org/hardhat-network/#solidity-optimizer-support
  69. optimizer: {
  70. enabled: true,
  71. runs: 200,
  72. },
  73. },
  74. },
  75. typechain: {
  76. outDir: "typechain",
  77. target: "ethers-v5",
  78. },
  79. };
  80. export default config;