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 "./tasks/deployers";
  8. import { resolve } from "path";
  9. import { config as dotenvConfig } from "dotenv";
  10. import { HardhatUserConfig } from "hardhat/config";
  11. import { NetworkUserConfig } from "hardhat/types";
  12. dotenvConfig({ path: resolve(__dirname, "./.env") });
  13. const chainIds = {
  14. ganache: 1337,
  15. goerli: 5,
  16. hardhat: 31337,
  17. kovan: 42,
  18. mainnet: 1,
  19. rinkeby: 4,
  20. ropsten: 3,
  21. };
  22. // Ensure that we have all the environment variables we need.
  23. const mnemonic: string | undefined = process.env.MNEMONIC;
  24. if (!mnemonic) {
  25. throw new Error("Please set your MNEMONIC in a .env file");
  26. }
  27. const infuraApiKey: string | undefined = process.env.INFURA_API_KEY;
  28. if (!infuraApiKey) {
  29. throw new Error("Please set your INFURA_API_KEY in a .env file");
  30. }
  31. function getChainConfig(network: keyof typeof chainIds): NetworkUserConfig {
  32. const url: string = "https://" + network + ".infura.io/v3/" + infuraApiKey;
  33. return {
  34. accounts: {
  35. count: 10,
  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: getChainConfig("goerli"),
  59. kovan: getChainConfig("kovan"),
  60. rinkeby: getChainConfig("rinkeby"),
  61. ropsten: getChainConfig("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. // 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;