<p>You could modify your datum type to something like so: {constants: {...}, old_datum: {...}}</p>
<p>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 &quot;for each input utxo, if that input resided at this script, enforce that there is some unique output utxo with the same constants&quot;.</p>

CC BY-SA 4.0
2022-10-16T04:20:16.653Z
Accidentally made a new answer when I meant to update old one.
micahkendall
CC BY-SA 4.0
2022-10-16T03:58:07.613Z
2022-10-16T03:58:07.613Z
micahkendall
<p>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?</p>
<p>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.</p>
<p>Finally, would it be possible to make this validation on-chain?</p>

<plutus-pioneer-program><smart-contract><statemachines>
How to create a smart contract constant variable?
# How to create a smart contract constant variable?

(Asked by: username_0 on 2022-01-14)

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?

**Tags:** plutus-pioneer-program, smart-contract, statemachines

---

## 1 answers

### Answer by username_1 on 2022-10-16. Score: 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".

> **Comments:**
> **username_1**: Accidentally made a new answer when I meant to update old one.  

---

