hardhat.config.ts 3.5 KB

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