Documentation
Loading...
CLI

Snapshots

Take and revert sandbox state snapshots

Take point-in-time snapshots of your sandbox state and revert to them at any time. Snapshots are useful for resetting your sandbox between test runs without creating a new sandbox.

[!NOTE] Snapshot commands require a live sandbox. Run buildbear status to confirm before proceeding.


snapshot take

Capture the current state of the sandbox and return a snapshot ID.

buildbear snapshot take [rpcUrl] [options]

Arguments:

ArgumentRequiredDescription
rpcUrlNoBuildBear RPC URL. If omitted, reads from .buildbear.json

Options:

FlagDescription
--jsonOutput as JSON
--quietSuppress output except errors

Example:

buildbear snapshot take

Output:

✓ Snapshot taken: 0x1

JSON output (--json):

{
  "snapshotId": "0x1"
}

Save the snapshot ID — you will need it to revert later.


snapshot revert

Roll the sandbox back to a previously taken snapshot.

buildbear snapshot revert [rpcUrl] --snapshot <snapshotId> [options]

Arguments:

ArgumentRequiredDescription
rpcUrlNoBuildBear RPC URL. If omitted, reads from .buildbear.json

Options:

FlagTypeRequiredDescription
--snapshot <snapshotId>stringYesSnapshot ID to revert to (hex format, e.g. 0x1)
--jsonflagNoOutput as JSON
--quietflagNoSuppress output except errors

Example:

buildbear snapshot revert --snapshot 0x1

Output:

✓ Reverted to snapshot 0x1

JSON output (--json):

{
  "snapshotId": "0x1",
  "success": true
}

How snapshots work

Snapshots use the standard evm_snapshot and evm_revert JSON-RPC methods, which are also supported by Hardhat and Anvil — so existing test helpers using these methods will work against BuildBear sandboxes.

A snapshot captures the entire EVM state: account balances, contract storage, deployed code, and nonces. Reverting to a snapshot does not automatically invalidate later snapshots — you can take multiple snapshots and revert between them.


Common pattern: snapshot before each test suite

#!/usr/bin/env bash
# deploy-and-test.sh

RPC=https://rpc.buildbear.io/my-sandbox-id

# Take a clean snapshot before running tests
SNAPSHOT=$(buildbear snapshot take $RPC --json | jq -r '.snapshotId')
echo "Snapshot: $SNAPSHOT"

# Run tests
npm test

# Revert so the next run starts from the same state
buildbear snapshot revert $RPC --snapshot "$SNAPSHOT"