Hardhat Network is a built-in local Ethereum network in Hardhat, designed specifically for development environments, with the following characteristics:
Main Features:
-
Instant Mining: Each transaction is automatically included in the next block without waiting for mining time, greatly speeding up development and testing.
-
Account Management: Provides 20 test accounts by default, each pre-allocated with 10000 ETH, facilitating testing of various scenarios.
-
Snapshot Functionality: Supports creating and restoring network state snapshots, allowing quick rollback to specific states during testing, ideal for testing reversible operations.
-
Gas Optimization: Gas fees are 0 in the local network, but gas usage is still calculated, helping developers optimize contracts.
-
Debugging Support: Provides Console.log functionality to output debug information in contracts, supports transaction tracing and error stack tracing.
-
Mainnet Forking: Can create forks based on Ethereum mainnet or testnet states to simulate real network environments for testing.
Differences from Real Networks:
- No need to wait for block confirmations
- Zero gas fees
- Pre-configured test accounts
- Advanced debugging features
- Ability to reset network state
Use Cases:
- Unit testing and integration testing
- Contract development and debugging
- DeFi protocol testing
- Transaction flow verification