hardhat.config.ts 3.1 KB

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