In addition to parameters that are explicitly declared in the definition, each transition also has the following implicit parameters available to it for each call.
The _sender
variable contains the account address that triggered this transition. In case, the transition was called by a contract account instead of a user account, then _sender
contains the contract address.
The _amount
contains the incoming amount ZIL
s sent by the sender. This amount must be explicitly accepted using the accept
statement within the transition. The money transfer does not happen if the transition does not execute accept.
Declare two new mutable variables in the contract:
user_address
of type ByStr20
with value 0x1234567890123456789012345678901234567890
user_tokens
of type Uint128
with value 0
in the contract.Then in the transition, assign these variables the value of _sender
and _amount
respectively.
Remember that the implicit variable _amount
has to be explicitly accepted. Use a simple accept
command in the first line of the transition changeName
.
Show Solution
scilla_version 0
contract SocialMediaPayment (owner: ByStr20)
field username: String = "Alice"
(*Declare the two new mutable variables below. You don’t need to use any semicolons to separate the lines outside the transitions*)
transition changeName(newname: String)
username := newname
(*Use ‘accept’ command in the line below which will accept the amount sent to this transition.*)
(*Assign the value of the implicit variables to the new mutable variables in the lines below. You’ll need to use the semicolons to separate the lines in the transition*)
end
12345678910111213