: string
The name of the issued token: uint64
: The issued amount of the token: Zen.Types.lock
: The recipient of the tokenopen
directive) a couple of useful modules (Zen.Base
, Zen.Cost
, and Zen.Data
) into the namespace, which we'll use later on.main
, and cf
.main
function is the function which runs with each execution of the contract, and cf
function is the function which describes the cost of the main
function.main
function, it should always have the following type signature:n
is the cost of the function and equal to cf txSkel context command sender messageBody wallet state
(notice that cf
doesn't take the contractId
as an argument, since the cost shouldn't depend on it).messageBody
parameter, in the form of a dictionary, which will contain the specified data as (key, value) pairs, where each key corresponds to one of the specified fields ("name", "amount", and "returnAddress").messageBody
is a dictionary, we need to try to extract a dictionary out of it - this is is done with the tryDict
function, defined in Zen.Data
.tryDict
function has the following type signature:data
type is a discriminated union of the following:tryDict
does, is taking a value of type data
, and if that value is a Collection(Dict(d))
- it returns Some d
, and otherwise it returns None
.messageBody
is already an option data
, we can't apply tryDict
on it directly (since it expects a data
), so instead we use the (>!=)
operator from Zen.Data
which have the following type signature:dict
, using a let
expression, so the main
function should now look like this:dict
will either contain a Some d
(where d
is a dictionary) or None
.tryFind
function (from Zen.Dictionary
).tryFind
function has the following type signature:Some
), and otherwise returns None
.dict
is an option (dictionary data) `cost` 64
we can't use tryFind
on it directly, so we'll use the (>?=)
operator (defined in Zen.Data
) instead.(>?=)
operator has the following type signature:Zen.Dictionary
module into the namespace with the open
directive)option data
value; to extract an actual lock out of that value we'll use the tryLock
function (defined in Zen.Data
):let!
expression.let!
usage strips the cost out of the declared variable (using the cost monad), so it would be easier to work with - the type of returnAddress
will be option lock
, instead of option lock `cost` m
.main
function should look like this:tryU64
and tryString
, respectively, instead of tryLock
):autoFailw
in Zen.ResultT
throws an error (within a ResultT
) and infers the cost automatically.fromSubtypeString
function from Zen.Asset
):begin
and end
here instead of parentheses, to make the code cleaner)txSkel
) with mint
, and then modifying the result with lockToAddress
(both are defined in Zen.TxSkeleton
):mint
and lockToAddress
return a costed txSkeleton
, so to chain them we're using the (>>=)
operator (bind) of the cost monad, and then we name the result using a let!
so we can use it as a "pure" txSkeleton
(instead of a costed txSkeleton
).ofTxSkel
from Zen.ContractResult
), and the contract is done:main
function, but we still need to define the cf
function.cf
is:cf
function to the end of the file, like this:0
and then lift it into the cost monad with Zen.Cost.ret
:cf
returns an int
, while it should return a nat
.cf
into a nat
, using the cast
function: