hardhat.config.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { config as dotenvConfig } from "dotenv";
  2. import { resolve } from "path";
  3. dotenvConfig({ path: resolve(__dirname, "./.env") });
  4. import { HardhatNetworkAccountsUserConfig } from "hardhat/types";
  5. import { HardhatUserConfig } from "hardhat/config";
  6. import "./tasks/accounts";
  7. import "./tasks/clean";
  8. import "@nomiclabs/hardhat-waffle";
  9. import "hardhat-typechain";
  10. import "solidity-coverage";
  11. /**
  12. * @dev You must have a `.env` file. Follow the example in `.env.example`.
  13. * @param {string} network The name of the testnet
  14. */
  15. function createNetworkConfig(
  16. network?: string,
  17. ): { accounts: HardhatNetworkAccountsUserConfig; url: string | undefined } {
  18. if (!process.env.MNEMONIC) {
  19. throw new Error("Please set your MNEMONIC in a .env file");
  20. }
  21. if (!process.env.INFURA_API_KEY) {
  22. throw new Error("Please set your INFURA_API_KEY");
  23. }
  24. return {
  25. accounts: {
  26. count: 10,
  27. initialIndex: 0,
  28. mnemonic: process.env.MNEMONIC,
  29. path: "m/44'/60'/0'/0",
  30. },
  31. url: network ? `https://${network}.infura.io/v3/${process.env.INFURA_API_KEY}` : undefined,
  32. };
  33. }
  34. const config: HardhatUserConfig = {
  35. defaultNetwork: "hardhat",
  36. mocha: {
  37. /* Without this property set, the "setTimeout" from the Greeter.js file wouldn't work. */
  38. delay: true,
  39. },
  40. networks: {
  41. hardhat: {
  42. chainId: 31337,
  43. },
  44. coverage: {
  45. url: "http://127.0.0.1:8555",
  46. },
  47. goerli: {
  48. ...createNetworkConfig("goerli"),
  49. chainId: 5,
  50. },
  51. kovan: {
  52. ...createNetworkConfig("kovan"),
  53. chainId: 42,
  54. },
  55. rinkeby: {
  56. ...createNetworkConfig("rinkeby"),
  57. chainId: 4,
  58. },
  59. ropsten: {
  60. ...createNetworkConfig("ropsten"),
  61. chainId: 3,
  62. },
  63. },
  64. paths: {
  65. artifacts: "./artifacts",
  66. cache: "./cache",
  67. // coverage: "./coverage",
  68. // coverageJson: "./coverage.json",
  69. sources: "./contracts",
  70. tests: "./test",
  71. },
  72. solidity: {
  73. version: "0.7.4",
  74. /* https://hardhat.org/hardhat-network/#solidity-optimizer-support */
  75. settings: {
  76. optimizer: {
  77. enabled: true,
  78. runs: 200,
  79. },
  80. },
  81. },
  82. typechain: {
  83. outDir: "typechain",
  84. target: "ethers-v5",
  85. },
  86. spdxLicenseIdentifier: {
  87. overwrite: false,
  88. runOnCompile: true,
  89. },
  90. };
  91. export default config;