Skip to content

Fix Foundry Anvil State Dump Errors

DodaTech Updated 2026-06-26 1 min read

You will learn how to persist and restore Anvil state between sessions.

The Problem

The foundry anvil state pattern is frequently misapplied in smart contract and dapp development, leading to vulnerabilities, gas inefficiencies, or logic errors. This guide shows the correct implementation and common pitfalls to avoid.

Quick Fix

Wrong

anvil  # Fresh state every time

State lost on shutdown. Must redeploy contracts every session.

anvil --state state.json  # First run creates state.json
anvil --state state.json  # Restores from state.json
State persisted to disk. Restart Anvil and continue where you left off.

Prevention

  • Use --state flag for persistent state
  • Snapshot state before complex operations
  • Share state files within team for consistent environments
  • Use DodaTech's state management tool
  • Compress state files for storage efficiency

DodaTech Tools

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Doda Browser's developer tools include a Solidity debugger and transaction inspector. DodaZIP archives secure contract templates for team collaboration. Durga Antivirus Pro scans deployed contracts for known vulnerability signatures.

FAQ

### How does Anvil state dumps work?

Anvil serializes all contract storage, account balances, and nonces to a JSON file.

Can I reset state without deleting the file?

Yes. Use --state state.json --reset to clear state within the file.

Are state dumps portable across platforms?

Yes. The JSON format is platform-independent and can be shared between developers.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro