Simulating transaction execution

Ethereum’s API has eth_call, which allows to simulate transaction execution without actually submitting transaction to the network. Tendermint’s ABCI has checkTx endpoint where transaction can be executed against current state to check it’s applicability.

Is there anything like that for DAML? Submission API has CreateCommand, ExerciseCommand, ExerciseByKeyCommand, CreateAndExerciseCommand. All of them are writes.

There are scenarios, where you want to know what transaction does before submitting it. Imagine having all of your business logic in DAML and then trying to create a “guard” which will examines if transaction should or should not be submitted. Impossible without replicating business logic outside of DAML.

1 Like

That’s an interesting question. What are the properties of a transaction that you would like to inspect that you could not cover with an abort or an ensure in your contract construction or exercising logic?

1 Like

Depending on what exactly you want to do Daml exceptions might be worth looking into: You can wrap the part that you want to test out in a try and run the checks at the end and then throw an exception if the checks fail to rollback everything that happened inside the try and do something else instead.

3 Likes