Functions
In fi, all variables are modified using strict functions. For example, you can't use a normal coding expression like this in fi:
Instead, we must use functions, for example:
With fi, all returned values MUST be used. For example:
This returns a value of int 30 which is left unused and will cause a compilation error.
Arithmetic functions
add(mixed,...) returns mixed
Returns the sum of two or more provided arguments, starting from left to right.
The Return type is defined by the inputs between the two values being evaluated:
This function can be used as standalone functions, or as a variable modifier.
sub(mixed,...) returns mixed
Returns the difference of two or more provided arguments, starting from left to right.
The Return type is defined by the inputs between the two values being evaluated:
This function can be used as standalone functions, or as a variable modifier.
mul(mixed,...) returns mixed
Returns the product of two or more provided arguments, starting from left to right.
The Return type is defined by the inputs between the two values being evaluated:
This function can be used as standalone functions, or as a variable modifier.
div(mixed,...) returns mixed
Returns the product of two or more provided arguments, starting from left to right.
The Return type is defined by the inputs between the two values being evaluated:
This function can be used as standalone functions, or as a variable modifier.
mod(mixed,...) returns mixed
Returns the remainder/mod of two or more provided arguments, starting from left to right.
The Return type is defined by the inputs between the two values being evaluated:
This function can be used as standalone functions, or as a variable modifier.
abs(int) returns nat
Returns the absolute value (unsigned) of the input int, returned as a nat.
neg(nat|int) returns int
Returns the negative signed value of the input, as an int.
sqr(mutez|nat|int) returns [same as input]
Returns the sqr of the input variable as the same type.
String & Byte functions
concat(bytes|string,...) returns [same as input]
Returns the concatenated inputs as the same output type. When using concat, all arguments must be of the same type (either bytes or string). Similar to arithmetic functions, multiple inputs can be concatenated from left to right.
This function can be used as standalone functions, or as a variable modifier.
concat_ws(string seperator, string...) returns string
Returns the concatenated inputs using the first string as a separator.
slice(string|bytes, nat offset, nat length) returns [same as first argument]
Returns the slice string or bytes starting from offset for length.
hash(bytes, ?algo) returns bytes
Returns the hashed bytes using the algorithm matching algo. Algo can be set to one of the following literals:
blake2b
sha256
sha512
If algo isn't provided, blake2b will be used by default.
pack(data) return bytes
Data of any type can be packed into byte form, which can be used for other purposes (as well as unpacking).
unpack(bytes, type) return mixed
The opposite to unpack - the packed bytes must be provided, as well as the type of the packed data. Will return the unpacked bytes as type.
verify(bytes, signature, key) returns bool
Verify will evaluate if the signature matches the provided key and bytes. Returns a bool.
Map/Set/List functions
All of these functions can be used as standalone functions, or as a variable modifier.
in(map|bmap|set, mixed val) returns bool
For map and bmap, returns true if mixed val is a valid key that exists within the map/bmap, otherwise returns false. For sets, this returns true if val is a vlid element that exists within the set.
length(map|list|set) returns nat
Returns the cardinal length/size of the map, list or set as a nat.
get(map|bmap, mixed val) returns mixed
Returns the element and type that corresponds to the map key val, or fails if it doesn't exist. We recommend using the in function first.
push(map|bmap, mixed key, mixed val) no return
Inserts or updates the element val with key. Does not return anything.
push(set, mixed val) no return
Inserts or updates the element val. Does not return anything.
drop(map|bmap|set, mixed val) no return
For maps and big maps, the element with the corresponding map key val is removed from the map. For sets, the element val is removed. Does not return anything.
pop(list) returns mixed
Returns the last item and type from list.
On-chain functions
transfer(address|pkh|key_hash|key|contract *, mutez, ?data) no return
Executes an on-chain operation to the provided address sending amount mutez. If data is present, we also send this as the parameter. The contract type must match the type of the data (if provided).
Nothing is returned.
delegate(?key_hash) no return
Sets the delegate for the contract - if key_hash is set than this is used, otherwise the contract is un-delegated if no argument is provided.
Nothing is returned.
Other functions
isset(?mixed) returns bool
Returns true if the optional value is not empty, otherwise it returns false.
none(type) returns ?type
Returns an optional value of type that is empty.
Last updated