hardhat.config.ts 2.3 KB

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