乐闻世界logo
搜索文章和话题

What are the main configuration items in Hardhat config file?

2月21日 15:58

Hardhat's configuration file hardhat.config.js (or .ts) is the core configuration file of the project, mainly containing the following configuration items:

Basic Configuration:

  1. Solidity Compiler Configuration
javascript
solidity: { version: "0.8.19", settings: { optimizer: { enabled: true, runs: 200 } } }
  1. Network Configuration
javascript
networks: { hardhat: { chainId: 31337 }, sepolia: { url: process.env.SEPOLIA_RPC_URL, accounts: [process.env.PRIVATE_KEY] }, mainnet: { url: process.env.MAINNET_RPC_URL, accounts: [process.env.PRIVATE_KEY] } }
  1. Path Configuration
javascript
paths: { sources: "./contracts", tests: "./test", cache: "./cache", artifacts: "./artifacts" }

Advanced Configuration:

  1. Plugin Configuration
javascript
require("@nomicfoundation/hardhat-toolbox"); require("@nomiclabs/hardhat-etherscan");
  1. Etherscan Verification Configuration
javascript
etherscan: { apiKey: process.env.ETHERSCAN_API_KEY }
  1. Gas Reporter Configuration
javascript
gasReporter: { enabled: true, currency: "USD" }

Best Practices:

  • Use environment variables to store sensitive information
  • Configure different networks for different environments (development, testing, production)
  • Enable compiler optimization to reduce gas consumption
  • Use TypeScript configuration files for type safety
  • Reasonably set the optimizer runs parameter
标签:Hardhat