hardhat.config.ts 3.2 KB

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