hardhat.config.ts 2.4 KB

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