🤔 Got questions? Schedule an office hours session.
Virtual TestNets
Develop
Revert State on TestNets

Revert State on TestNets

Reverting state can be helpful when testing contracts and protocols and you want to discard all state changes up to the snapshot position.

Instead of reverting state, consider forking an existing testnet instead, and do your testing on a disposable working copy.

Reverting to a snapshot

Create snapshot

Use evm_snapshot to create a snapshot on the current block. The method returns the snapshot ID you can use to revert.

snapshot.sh
TENDERLY_VIRTUAL_TESTNET_RPC= #...
 
SNAPSHOT_ID=$(curl $TENDERLY_VIRTUAL_TESTNET_RPC \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{
      "jsonrpc": "2.0",
      "method": "evm_snapshot",
      "id": "1234"
    }' \
    | jq -r  '.result')

Revert

Use evm_revert to back revert to previously created snapshot (SNAPSHOT_ID). From this point onwards, all prior changes up to the snapshot will be discarded.

revert.sh
read -r -d '' REVERT_REQUEST <<EOF
{
  "jsonrpc": "2.0",
  "method": "evm_revert",
  "params": ["$SNAPSHOT_ID"],
  "id": "1234"
}
EOF
 
curl $TENDERLY_VIRTUAL_TESTNET_RPC \
    -H "Content-Type: application/json" \
    -d $REVERT_REQUEST