How to Point the Fork to a Specific Simulation

Updating the fork - Timemachine

At some point, you may want to reset the Fork and discard all transactions and state changes incurred from your simulations. We can do this by updating the “head” of the Fork. The head is a reference to a Simulation on top of which new Simulations are done. Effectively, it points to the last executed Simulation.
In this example, we’ll move where the head points, so we’re literally “removing” or “forgetting” transactions that had happened since that particular Simulation. In other words, we’re going back in time:
API Typescript
1
const req = {
2
fork_head: respTxApprove.simulation.ID
3
}
4
5
const fork = await axios.put(tenderlyAPI, "fork", req)
Copied!

Moving the fork using JSON-RPC

If you’re doing transactions on Tenderly by connecting your Web3 provider (ethers.js) to a Tenderly JSON-RPC provider, you can achieve the same by invoking evm_snapshot and evm_reset:
1
contract.send(...) // 1
2
contract.send(...) // 2
3
// get an ID of last transaction, think git tag
4
const checkpoint = provider.send("evm_snapshot", []);
5
6
contract.send(...) // 3
7
contract.send(...) // 4
8
9
// revert back the checkpoint
10
provider.send("evm_revert", [checkpoint]);
11
12
// head becomes 2
Copied!