hardhat.config.ts 3.6 KB

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