As stated earlier, the variable declared in the transition is a temporary variable that is not stored on the blockchain and exists only while the contract is being run.
We can use these temporary variables to get values from the user input, mutable variables etc., and then perform operations on these values.
Then, in order to ensure that blockchain contains the final value, it has to be transferred to a mutable variable.
You’ll note that the design of Scilla language is making a user be very cautious about updating any value assigned to a mutable variable. That is so because changing a mutable variable is a critical operation and if done in a wrong manner, it could lead to security issues. We’ll explore this in more detail in later chapters.
At the moment, we simply need to assign the value of the temporary variable to the mutable variable. We use the :=
operator for this type of assignment.
Update the mutable variable username
with the value of the temporary variable newname
in the body of the transition.
Show Solution
scilla_version 0
contract SocialMediaPayment (owner: ByStr20)
field username: String = "Alice"
transition changeName()
newname = "Bob" (* Now that we’ll be having another line, don’t forget to include a semicolon at the end of the previous line, i.e. after "Bob" *)
(* Start typing from the line below *)
end
12345678910