hardhat.config.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. const mnemonic = process.env.MNEMONIC;
  23. if (!mnemonic) {
  24. throw new Error("Please set your MNEMONIC in a .env file");
  25. }
  26. const infuraApiKey = process.env.INFURA_API_KEY;
  27. if (!infuraApiKey) {
  28. throw new Error("Please set your INFURA_API_KEY in a .env file");
  29. }
  30. function createTestnetConfig(network: keyof typeof chainIds): NetworkUserConfig {
  31. const url: string = "https://" + network + ".infura.io/v3/" + infuraApiKey;
  32. return {
  33. accounts: {
  34. count: 10,
  35. initialIndex: 0,
  36. mnemonic,
  37. path: "m/44'/60'/0'/0",
  38. },
  39. chainId: chainIds[network],
  40. url,
  41. };
  42. }
  43. const config: HardhatUserConfig = {
  44. defaultNetwork: "hardhat",
  45. gasReporter: {
  46. currency: "USD",
  47. enabled: process.env.REPORT_GAS ? true : false,
  48. excludeContracts: [],
  49. src: "./contracts",
  50. },
  51. networks: {
  52. hardhat: {
  53. accounts: {
  54. mnemonic,
  55. },
  56. chainId: chainIds.hardhat,
  57. },
  58. goerli: createTestnetConfig("goerli"),
  59. kovan: createTestnetConfig("kovan"),
  60. rinkeby: createTestnetConfig("rinkeby"),
  61. ropsten: createTestnetConfig("ropsten"),
  62. },
  63. paths: {
  64. artifacts: "./artifacts",
  65. cache: "./cache",
  66. sources: "./contracts",
  67. tests: "./test",
  68. },
  69. solidity: {
  70. version: "0.8.6",
  71. settings: {
  72. metadata: {
  73. // Not including the metadata hash
  74. // https://github.com/paulrberg/solidity-template/issues/31
  75. bytecodeHash: "none",
  76. },
  77. // You should disable the optimizer when debugging
  78. // https://hardhat.org/hardhat-network/#solidity-optimizer-support
  79. optimizer: {
  80. enabled: true,
  81. runs: 800,
  82. },
  83. },
  84. },
  85. typechain: {
  86. outDir: "typechain",
  87. target: "ethers-v5",
  88. },
  89. };
  90. export default config;