2

I know about tools like ganache-time-traveler that let you advance the block number.

But is it possible to go back to a lower value?

2

The only option to do this is to use the takeSnapshot and revertToSnapshot functions in that same repo.

When you are at a state you know you want to return to, call takeSnapshot in order to get a snapshot ID. When you want to revert to that state, simply run revertToSnapshot with that specific ID.

As a note, the snapshotting function in Ganache was finicky the last time I used it (Feb 2019). There were certain limitations, such as not being able to take multiple snapshots before reverting to one. I do not know the current status of this.


Edit

The issues I was having with this feature are addressed in the "Custom Methods" section of the ganache-cli repo:

evm_snapshot : Snapshot the state of the blockchain at the current block. Takes no parameters. Returns the integer id of the snapshot created. A snapshot can only be used once. After a successful evm_revert, the same snapshot id cannot be used again. Consider creating a new snapshot after each evm_revert if you need to revert to the same point multiple times.

evm_revert : Revert the state of the blockchain to a previous snapshot. Takes a single parameter, which is the snapshot id to revert to. This deletes the given snapshot, as well as any snapshots taken after (Ex: reverting to id 0x1 will delete snapshots with ids 0x1, 0x2, etc... If no snapshot id is passed it will revert to the latest snapshot. Returns true.

  • 1
    I used this, but it doesn't seem to lower the block number. It just resets the timestamp. – Paul Berg Sep 19 at 16:38
  • I wonder if that is a ganache-time-traveler specific thing? I do not see anything about it in the actual ganache-cli repo – shane Sep 19 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.