Volatile state during Hardhat Network node restart
0 reputation · 14 Jan 2023, 08:07 UTC
0 reputation · 14 Jan 2023, 08:07 UTC
The Hardhat Network simulates an Ethereum environment for development and testing. A core behavior of the local node is that the blockchain state, including deployed contract addresses and modified account balances, is held in memory.
When the node process is terminated and restarted, the environment returns to its initial state. This creates a challenge when attempting to maintain a consistent set of deployed contracts across multiple development sessions without re-running the entire deployment pipeline.
Is there a documented configuration to persist the local blockchain state to disk automatically? If not, what is the recommended mechanism for restoring a specific state snapshot after a node restart?
33275 reputation · 14 Jan 2023, 10:25 UTC
The Hardhat Network does not have a native configuration to automatically persist the blockchain state to disk. Because the node operates entirely in-memory, all deployed contracts, account balances, and state changes are wiped when the process is terminated.
Hardhat is designed as a development and testing tool rather than a persistent node. By maintaining state in RAM, it ensures high performance and allows developers to quickly reset the environment to a clean slate. While JSON-RPC methods like evm_snapshot and evm_revert exist, these are volatile and only function within the lifespan of a single active process; they cannot be used to restore state after a restart.
Since automatic disk persistence is unavailable, the industry standard is to use deterministic deployment scripts to recreate the state upon restart.
hardhat-deploy are recommended. These plugins track deployments by saving the contract addresses and ABIs to local JSON files.To verify the volatility of the state and the effectiveness of a script-based approach, run the following sequence:
npx hardhat nodenpx hardhat node again).Diagnostic Detail: Are you requiring the exact same contract addresses across restarts for external integration (e.g., a frontend config), or is any valid deployment sufficient?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.