hardhat.config.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import "@nomiclabs/hardhat-waffle";
  2. import "@nomiclabs/hardhat-etherscan";
  3. import "@typechain/hardhat";
  4. import "hardhat-gas-reporter";
  5. import "solidity-coverage";
  6. import "./tasks/accounts";
  7. import "./tasks/deploy";
  8. import { resolve } from "path";
  9. import { config as dotenvConfig } from "dotenv";
  10. import { HardhatUserConfig } from "hardhat/config";
  11. import { NetworkUserConfig } from "hardhat/types";
  12. dotenvConfig({ path: resolve(__dirname, "./.env") });
  13. const chainIds = {
  14. goerli: 5,
  15. hardhat: 31337,
  16. kovan: 42,
  17. mainnet: 1,
  18. rinkeby: 4,
  19. ropsten: 3,
  20. };
  21. // Ensure that we have all the environment variables we need.
  22. const mnemonic: string | undefined = process.env.MNEMONIC;
  23. if (!mnemonic) {
  24. throw new Error("Please set your MNEMONIC in a .env file");
  25. }
  26. const infuraApiKey: string | undefined = process.env.INFURA_API_KEY;
  27. if (!infuraApiKey) {
  28. throw new Error("Please set your INFURA_API_KEY in a .env file");
  29. }
  30. function getChainConfig(network: keyof typeof chainIds): NetworkUserConfig {
  31. const url: string = "https://" + network + ".infura.io/v3/" + infuraApiKey;
  32. return {
  33. accounts: {
  34. count: 10,
  35. mnemonic,
  36. path: "m/44'/60'/0'/0",
  37. },
  38. chainId: chainIds[network],
  39. url,
  40. };
  41. }
  42. const config: HardhatUserConfig = {
  43. defaultNetwork: "hardhat",
  44. etherscan: {
  45. apiKey: {
  46. arbitrumOne: process.env.ARBSCAN_API_KEY,
  47. arbitrumTestnet: process.env.ARBSCAN_API_KEY,
  48. avalanche: process.env.SNOWTRACE_API_KEY,
  49. bsc: process.env.BSCSCAN_API_KEY,
  50. goerli: process.env.ETHERSCAN_API_KEY,
  51. kovan: process.env.ETHERSCAN_API_KEY,
  52. mainnet: process.env.ETHERSCAN_API_KEY,
  53. optimisticEthereum: process.env.OPTIMISM_API_KEY,
  54. polygon: process.env.POLYGONSCAN_API_KEY,
  55. rinkeby: process.env.ETHERSCAN_API_KEY,
  56. ropsten: process.env.ETHERSCAN_API_KEY,
  57. },
  58. },
  59. gasReporter: {
  60. currency: "USD",
  61. enabled: process.env.REPORT_GAS ? true : false,
  62. excludeContracts: [],
  63. src: "./contracts",
  64. },
  65. networks: {
  66. hardhat: {
  67. accounts: {
  68. mnemonic,
  69. },
  70. chainId: chainIds.hardhat,
  71. },
  72. goerli: getChainConfig("goerli"),
  73. kovan: getChainConfig("kovan"),
  74. rinkeby: getChainConfig("rinkeby"),
  75. ropsten: getChainConfig("ropsten"),
  76. },
  77. paths: {
  78. artifacts: "./artifacts",
  79. cache: "./cache",
  80. sources: "./contracts",
  81. tests: "./test",
  82. },
  83. solidity: {
  84. version: "0.8.9",
  85. settings: {
  86. metadata: {
  87. // Not including the metadata hash
  88. // https://github.com/paulrberg/solidity-template/issues/31
  89. bytecodeHash: "none",
  90. },
  91. // Disable the optimizer when debugging
  92. // https://hardhat.org/hardhat-network/#solidity-optimizer-support
  93. optimizer: {
  94. enabled: true,
  95. runs: 800,
  96. },
  97. },
  98. },
  99. typechain: {
  100. outDir: "src/types",
  101. target: "ethers-v5",
  102. },
  103. };
  104. export default config;