You can capture the entire state of a Blockchain instance (including all contracts, network config, transaction lt, unix timestamp, verbosity, and libraries) and restore it later. This is useful for resetting tests to a known configuration point.
Basic usage:
const snapshot = blockchain.snapshot();
// ... later ...
await blockchain.loadFrom(snapshot);
Serializing snapshots for disk/network storage:
Since snapshots contain Cells and Buffers which are not JSON-safe, use snapshotToSerializable and snapshotFromSerializable to convert them to plain JSON objects.
import { snapshotToSerializable, snapshotFromSerializable } from './BlockchainSnapshot';
// Save to disk
const serializable = snapshotToSerializable(blockchain.snapshot());
fs.writeFileSync('snapshot.json', JSON.stringify(serializable));
// Restore from disk
const snapshotJson = JSON.parse(fs.readFileSync('snapshot.json', 'utf8'));
await blockchain.loadFrom(snapshotFromSerializable(snapshotJson));
import { snapshotToSerializable, snapshotFromSerializable } from './BlockchainSnapshot';
// Capture and serialize
const serializable = snapshotToSerializable(blockchain.snapshot());
// Restore from serialized object
const restored = snapshotFromSerializable(serializable);
await blockchain.loadFrom(restored);