hardhat.config.ts 2.3 KB

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