I am using state machines to create a smart contract. How can I create a variable that will be defined by the user when it runs the first step of the state machine and that then can't be modified anymore?

In other words, it's a variable that is created by using the smart contract endpoints but that can't be modified later on until the state machine reaches its end.

Finally, would it be possible to make this validation on-chain?

1 Answer 1


You could modify your datum type to something like so: {constants: {...}, old_datum: {...}}

Then, make your old validations take old_datum (you could unwrap old_datum as the same name as your current datum even), and validate output constants==input constants. You will want an exception to this rule if the input does not come from the script, to allow setting the constants at first, so you could logically enforce something like "for each input utxo, if that input resided at this script, enforce that there is some unique output utxo with the same constants".

  • Accidentally made a new answer when I meant to update old one. Oct 16, 2022 at 4:20

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.