hardhat.config.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. networks: {
  49. hardhat: {
  50. accounts: {
  51. mnemonic,
  52. },
  53. chainId: chainIds.hardhat,
  54. },
  55. goerli: createTestnetConfig("goerli"),
  56. kovan: createTestnetConfig("kovan"),
  57. rinkeby: createTestnetConfig("rinkeby"),
  58. ropsten: createTestnetConfig("ropsten"),
  59. },
  60. paths: {
  61. artifacts: "./artifacts",
  62. cache: "./cache",
  63. sources: "./contracts",
  64. tests: "./test",
  65. },
  66. solidity: {
  67. version: "0.8.1",
  68. settings: {
  69. // https://hardhat.org/hardhat-network/#solidity-optimizer-support
  70. optimizer: {
  71. enabled: true,
  72. runs: 200,
  73. },
  74. },
  75. },
  76. typechain: {
  77. outDir: "typechain",
  78. target: "ethers-v5",
  79. },
  80. };
  81. export default config;