Skip to main content

Usage

dokrypt snapshot <subcommand> [flags]

Subcommands

SubcommandDescription
saveSave current chain state
restoreRestore to a saved snapshot
listList all snapshots
deleteDelete a snapshot
exportExport snapshot to a file
importImport snapshot from a file
diffCompare two snapshots

save

Save the current chain state as a named snapshot.
dokrypt snapshot save <name> [flags]

Arguments

ArgumentRequiredDescription
nameYesSnapshot name (used for restore/delete)

Flags

FlagTypeDefaultDescription
--descriptionstringHuman-readable description
--tagsstring[]Tags for categorization (repeatable)

How It Works

  1. Calls evm_snapshot via JSON-RPC on the running chain
  2. Records the current block number and chain ID
  3. Saves metadata to ~/.dokrypt/snapshots/<project>/<name>.json

Examples

# Simple save
dokrypt snapshot save initial-state

# With description
dokrypt snapshot save before-deploy --description "Clean state before contract deployment"

# With tags
dokrypt snapshot save checkpoint --tags critical --tags v1.0

restore

Restore chain state to a previously saved snapshot.
dokrypt snapshot restore <name>

Arguments

ArgumentRequiredDescription
nameYesSnapshot name to restore

How It Works

  1. Loads the snapshot metadata
  2. Calls evm_revert with the snapshot ID
  3. Takes a new snapshot at the same point (EVM snapshots are consumed on revert)
  4. Returns the current block number

Examples

dokrypt snapshot restore initial-state
EVM snapshots are single-use — once reverted, the snapshot ID is consumed. Dokrypt automatically takes a new snapshot after restoring so you can restore again later.

list

List all snapshots for the current project.
dokrypt snapshot list

Output

Name              Block    Created              Description
initial-state     0        2025-01-15 10:30:00  Fresh state
before-deploy     42       2025-01-15 10:35:00  Before contract deployment
after-tests       108      2025-01-15 10:42:00  After running test suite
Snapshots are sorted by creation time (newest first).

delete

Delete a saved snapshot.
dokrypt snapshot delete <name>

Examples

dokrypt snapshot delete old-checkpoint

export

Export a snapshot to a JSON file for sharing or backup.
dokrypt snapshot export <name> <path>

Arguments

ArgumentRequiredDescription
nameYesSnapshot name
pathYesOutput file path

How It Works

  1. Loads snapshot metadata
  2. Calls anvil_dumpState to export the full chain state
  3. Writes a JSON file containing both metadata and state data

Examples

dokrypt snapshot export initial-state ./backups/state.json
The exported file contains:
{
  "metadata": {
    "name": "initial-state",
    "block_number": 0,
    "chain_id": 31337,
    "created_at": "2025-01-15T10:30:00Z"
  },
  "state": { ... }
}
anvil_dumpState is Anvil-specific. Export may not work with Hardhat or Geth chains.

import

Import a snapshot from a JSON file.
dokrypt snapshot import <path>

Arguments

ArgumentRequiredDescription
pathYesPath to the snapshot JSON file

How It Works

  1. Reads and parses the JSON file
  2. Loads the chain state via anvil_loadState
  3. Saves the metadata to the local snapshot registry

Examples

dokrypt snapshot import ./backups/state.json

diff

Show differences between two snapshots.
dokrypt snapshot diff <snap1> <snap2>

Arguments

ArgumentRequiredDescription
snap1YesFirst snapshot name
snap2YesSecond snapshot name

Output

Shows the block number delta and time difference between snapshots.

Examples

dokrypt snapshot diff before-deploy after-deploy
Comparing: before-deploy vs after-deploy
  Block delta: +66 blocks (42 → 108)
  Time delta:  7m12s