hardhat.config.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. ganache: 1337,
  26. hardhat: 31337,
  27. mainnet: 1,
  28. "optimism-mainnet": 10,
  29. "polygon-mainnet": 137,
  30. "polygon-mumbai": 80001,
  31. sepolia: 11155111,
  32. };
  33. function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig {
  34. let jsonRpcUrl: string;
  35. switch (chain) {
  36. case "avalanche":
  37. jsonRpcUrl = "https://api.avax.network/ext/bc/C/rpc";
  38. break;
  39. case "bsc":
  40. jsonRpcUrl = "https://bsc-dataseed1.binance.org";
  41. break;
  42. default:
  43. jsonRpcUrl = "https://" + chain + ".infura.io/v3/" + infuraApiKey;
  44. }
  45. return {
  46. accounts: {
  47. count: 10,
  48. mnemonic,
  49. path: "m/44'/60'/0'/0",
  50. },
  51. chainId: chainIds[chain],
  52. url: jsonRpcUrl,
  53. };
  54. }
  55. const config: HardhatUserConfig = {
  56. defaultNetwork: "hardhat",
  57. namedAccounts: {
  58. deployer: 0,
  59. },
  60. etherscan: {
  61. apiKey: {
  62. arbitrumOne: process.env.ARBISCAN_API_KEY || "",
  63. avalanche: process.env.SNOWTRACE_API_KEY || "",
  64. bsc: process.env.BSCSCAN_API_KEY || "",
  65. mainnet: process.env.ETHERSCAN_API_KEY || "",
  66. optimisticEthereum: process.env.OPTIMISM_API_KEY || "",
  67. polygon: process.env.POLYGONSCAN_API_KEY || "",
  68. polygonMumbai: process.env.POLYGONSCAN_API_KEY || "",
  69. sepolia: process.env.ETHERSCAN_API_KEY || "",
  70. },
  71. },
  72. gasReporter: {
  73. currency: "USD",
  74. enabled: process.env.REPORT_GAS ? true : false,
  75. excludeContracts: [],
  76. src: "./contracts",
  77. },
  78. networks: {
  79. hardhat: {
  80. accounts: {
  81. mnemonic,
  82. },
  83. chainId: chainIds.hardhat,
  84. },
  85. ganache: {
  86. accounts: {
  87. mnemonic,
  88. },
  89. chainId: chainIds.ganache,
  90. url: "http://localhost:8545",
  91. },
  92. arbitrum: getChainConfig("arbitrum-mainnet"),
  93. avalanche: getChainConfig("avalanche"),
  94. bsc: getChainConfig("bsc"),
  95. mainnet: getChainConfig("mainnet"),
  96. optimism: getChainConfig("optimism-mainnet"),
  97. "polygon-mainnet": getChainConfig("polygon-mainnet"),
  98. "polygon-mumbai": getChainConfig("polygon-mumbai"),
  99. sepolia: getChainConfig("sepolia"),
  100. },
  101. paths: {
  102. artifacts: "./artifacts",
  103. cache: "./cache",
  104. sources: "./contracts",
  105. tests: "./test",
  106. },
  107. solidity: {
  108. version: "0.8.17",
  109. settings: {
  110. metadata: {
  111. // Not including the metadata hash
  112. // https://github.com/paulrberg/hardhat-template/issues/31
  113. bytecodeHash: "none",
  114. },
  115. // Disable the optimizer when debugging
  116. // https://hardhat.org/hardhat-network/#solidity-optimizer-support
  117. optimizer: {
  118. enabled: true,
  119. runs: 800,
  120. },
  121. },
  122. },
  123. typechain: {
  124. outDir: "types",
  125. target: "ethers-v6",
  126. },
  127. };
  128. export default config;