hardhat.config.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import "@nomicfoundation/hardhat-toolbox";
  2. import { config as dotenvConfig } from "dotenv";
  3. import type { HardhatUserConfig } from "hardhat/config";
  4. import type { NetworkUserConfig } from "hardhat/types";
  5. import { resolve } from "path";
  6. import "./tasks/accounts";
  7. import "./tasks/deploy";
  8. const dotenvConfigPath: string = process.env.DOTENV_CONFIG_PATH || "./.env";
  9. dotenvConfig({ path: resolve(__dirname, dotenvConfigPath) });
  10. // Ensure that we have all the environment variables we need.
  11. const mnemonic: string | undefined = process.env.MNEMONIC;
  12. if (!mnemonic) {
  13. throw new Error("Please set your MNEMONIC in a .env file");
  14. }
  15. const infuraApiKey: string | undefined = process.env.INFURA_API_KEY;
  16. if (!infuraApiKey) {
  17. throw new Error("Please set your INFURA_API_KEY in a .env file");
  18. }
  19. const chainIds = {
  20. "arbitrum-mainnet": 42161,
  21. avalanche: 43114,
  22. bsc: 56,
  23. hardhat: 31337,
  24. mainnet: 1,
  25. "optimism-mainnet": 10,
  26. "polygon-mainnet": 137,
  27. "polygon-mumbai": 80001,
  28. rinkeby: 4,
  29. };
  30. function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig {
  31. let jsonRpcUrl: string;
  32. switch (chain) {
  33. case "avalanche":
  34. jsonRpcUrl = "https://api.avax.network/ext/bc/C/rpc";
  35. break;
  36. case "bsc":
  37. jsonRpcUrl = "https://bsc-dataseed1.binance.org";
  38. break;
  39. default:
  40. jsonRpcUrl = "https://" + chain + ".infura.io/v3/" + infuraApiKey;
  41. }
  42. return {
  43. accounts: {
  44. count: 10,
  45. mnemonic,
  46. path: "m/44'/60'/0'/0",
  47. },
  48. chainId: chainIds[chain],
  49. url: jsonRpcUrl,
  50. };
  51. }
  52. const config: HardhatUserConfig = {
  53. defaultNetwork: "hardhat",
  54. etherscan: {
  55. apiKey: {
  56. arbitrumOne: process.env.ARBISCAN_API_KEY || "",
  57. avalanche: process.env.SNOWTRACE_API_KEY || "",
  58. bsc: process.env.BSCSCAN_API_KEY || "",
  59. mainnet: process.env.ETHERSCAN_API_KEY || "",
  60. optimisticEthereum: process.env.OPTIMISM_API_KEY || "",
  61. polygon: process.env.POLYGONSCAN_API_KEY || "",
  62. polygonMumbai: process.env.POLYGONSCAN_API_KEY || "",
  63. rinkeby: process.env.ETHERSCAN_API_KEY || "",
  64. },
  65. },
  66. gasReporter: {
  67. currency: "USD",
  68. enabled: process.env.REPORT_GAS ? true : false,
  69. excludeContracts: [],
  70. src: "./contracts",
  71. },
  72. networks: {
  73. hardhat: {
  74. accounts: {
  75. mnemonic,
  76. },
  77. chainId: chainIds.hardhat,
  78. },
  79. arbitrum: getChainConfig("arbitrum-mainnet"),
  80. avalanche: getChainConfig("avalanche"),
  81. bsc: getChainConfig("bsc"),
  82. mainnet: getChainConfig("mainnet"),
  83. optimism: getChainConfig("optimism-mainnet"),
  84. "polygon-mainnet": getChainConfig("polygon-mainnet"),
  85. "polygon-mumbai": getChainConfig("polygon-mumbai"),
  86. rinkeby: getChainConfig("rinkeby"),
  87. },
  88. paths: {
  89. artifacts: "./artifacts",
  90. cache: "./cache",
  91. sources: "./contracts",
  92. tests: "./test",
  93. },
  94. solidity: {
  95. version: "0.8.15",
  96. settings: {
  97. metadata: {
  98. // Not including the metadata hash
  99. // https://github.com/paulrberg/hardhat-template/issues/31
  100. bytecodeHash: "none",
  101. },
  102. // Disable the optimizer when debugging
  103. // https://hardhat.org/hardhat-network/#solidity-optimizer-support
  104. optimizer: {
  105. enabled: true,
  106. runs: 800,
  107. },
  108. },
  109. },
  110. typechain: {
  111. outDir: "src/types",
  112. target: "ethers-v5",
  113. },
  114. };
  115. export default config;