hardhat.config.ts 3.4 KB

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