Skip to main content

Simulations

The EVC also supports executing batches in a simulation mode. This is only intended to be invoked "off-chain", and is useful for user interfaces because they can show the user what the expected outcome of a sequence of operations will be.

Simulations work by actually performing the requested operations but then reverting, which (if called on-chain) reverts all the effects. Although simple in principle, there are a number of design elements involved:

  • Intermediate read-only queries can be inserted into a batch to gather simulated data useful for display
  • The results are available even if status checks would cause a failure, for example so that a user can see exactly what is causing the failure
  • Although internally simulations work by reverting, the recommended interface returns it as regular return data, which causes fewer compatibility problems (sometimes error data is mangled or dropped). This is the reason for batchRevert: You can't do a "try/catch" without an external call, so this must be an external function, although we recommend using the batchSimulation entry point instead.
  • Simulations don't have the side-effect of making regular batches create large return-data (which would be gas inefficient)