hardhat.config.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { config as dotenvConfig } from "dotenv";
  2. import { resolve } from "path";
  3. dotenvConfig({ path: resolve(__dirname, "./.env") });
  4. import { HardhatUserConfig } from "hardhat/config";
  5. import { NetworkUserConfig } from "hardhat/types";
  6. import "./tasks/accounts";
  7. import "./tasks/clean";
  8. import "@nomiclabs/hardhat-waffle";
  9. import "hardhat-typechain";
  10. import "solidity-coverage";
  11. const chainIds = {
  12. ganache: 1337,
  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. let mnemonic: string;
  22. if (!process.env.MNEMONIC) {
  23. throw new Error("Please set your MNEMONIC in a .env file");
  24. } else {
  25. mnemonic = process.env.MNEMONIC;
  26. }
  27. let infuraApiKey: string;
  28. if (!process.env.INFURA_API_KEY) {
  29. throw new Error("Please set your INFURA_API_KEY in a .env file");
  30. } else {
  31. infuraApiKey = process.env.INFURA_API_KEY;
  32. }
  33. function createTestnetConfig(network: keyof typeof chainIds): NetworkUserConfig {
  34. const url: string = "https://" + network + ".infura.io/v3/" + infuraApiKey;
  35. return {
  36. accounts: {
  37. count: 10,
  38. initialIndex: 0,
  39. mnemonic,
  40. path: "m/44'/60'/0'/0",
  41. },
  42. chainId: chainIds[network],
  43. url,
  44. };
  45. }
  46. const config: HardhatUserConfig = {
  47. defaultNetwork: "hardhat",
  48. mocha: {
  49. // Without this property set, the "setTimeout" from the Greeter.js file wouldn't work.
  50. delay: true,
  51. },
  52. networks: {
  53. hardhat: {
  54. chainId: chainIds.hardhat,
  55. },
  56. goerli: createTestnetConfig("goerli"),
  57. kovan: createTestnetConfig("kovan"),
  58. rinkeby: createTestnetConfig("rinkeby"),
  59. ropsten: createTestnetConfig("ropsten"),
  60. },
  61. paths: {
  62. artifacts: "./artifacts",
  63. cache: "./cache",
  64. coverage: "./coverage",
  65. coverageJson: "./coverage.json",
  66. sources: "./contracts",
  67. tests: "./test",
  68. },
  69. solidity: {
  70. version: "0.7.4",
  71. settings: {
  72. // https://hardhat.org/hardhat-network/#solidity-optimizer-support
  73. optimizer: {
  74. enabled: true,
  75. runs: 200,
  76. },
  77. },
  78. },
  79. typechain: {
  80. outDir: "typechain",
  81. target: "ethers-v5",
  82. },
  83. };
  84. export default config;