Some validator scripts can be implemented with or without state machine. This is a decision that has to be made by the developer.

I wonder what are the pros and cons of using state machine. What factors should be considered when making the decision.

1 Answer 1


A state-machine gives you a framework for testing and reasoning about your code. It's generally much easier to think in terms of state machines where transactions are transitions, every transaction is one transition from one state into another, so knowing the initial conditions, you can think about what should be the outcome and test for it.

One "direct drawback" of representing things as state machine is that it forces you to include datums of both inputs you spent but also outputs you send to (since your validator must control the transition goes into the right state). There are cases where you may not want to reveal the datum upfront and obfuscating behind a hash is quite handy.

Another drawback is the maturity / usability of the current state machine framework in PlutusTx. Works well enough for simple scenarios but gets in the way of more complex cases and, adds a non negligible overhead. Yet, implementing a state-machine by hand is relatively easy.

  • Can you provide some example for "gets in the way of more complex cases"?
    – uhbif19
    Dec 1, 2023 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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