Builtins
A B
abs(t : T)
Returns the absolute value of input t
.
When t
is of type:
The function may be considered as a non-failing conversion function from int
to nat
.
Parameter
Returns
R
t
add(s : set<T>, e : T)
s
augmented with element e
.If e
is already present in s
, it returns a copy of s
.Parameters
e
:
T
Returns
address_to_contract<T>(a : address)
Converts address a
to a contract<T>
value to be used as parameter of make_operation
.
T
is:
unit
for an account address (tz1...
)- the type of the parameter section for a contract address
get_entrypoint
builtin.Parameter
Returns
option<contract<T>>
none
when the address or the path to entrypoint is invalidsome
of acontract<T>
value
apply_lambda(f : lambda<A * T, R>, x : A)
Executes partial application of a lambda value f
to an argument value x
.
For example:
const plus_x = lambda<nat>((a : nat * nat) -> a[0] + a[1]);
const plus_three = apply_lambda(plus_x, 3);
const r = exec_lambda(plus_three, 1);
/* r is equal to 4 */
Parameters
f
:
lambda<A*T,R>
x
:
A
Returns
blake2b(b : bytes)
bytes_to_nat(b : bytes)
Parameter
Returns
C D
call_view<T>(a : address, id : string, arg : X)
Calls a contract's view and returns an option<T>
of the result.
For example, consider the following view declaration in contract A
:
view affine(x : rational) : rational {
return (2 * x + 3)
}
Call this function from contract B
with:
const r ?= call_view<rational>(addr_A, "affine", -3/2) : "AFFINE_ERR"
When calling a local view (defined in current contract), it is sufficient to prefix the view name by self.
. For example, calling the local affine
view is done as follows:
const r ?= self.affine(-3/2) : "AFFINE_ERR"
Parameters
arg
:
X
Returns
none
if a problem occured (view not found, or view execution failed)some(v)
,v
being the value returned by the view
ceil(r : rational)
Parameter
Returns
check_signature(k : key, s : signature, b : bytes)
s
is obtained by signing sequence of bytes b
with account public key k
.Parameters
Returns
concat
Concatenates two values of type string
, bytes
, or list<T>
, or a list of values of type string
or bytes
.
String
Concatenates two string
values.
For example:
const m = concat("Hello ", "Archetype");
/* m is "Hello Archetype" */
It is equivalent to the +
operator.
Bytes
Concatenates two bytes
values.
For example:
const m = concat(0x48656c6c6f, 0x417263686574797065);
/* m is 0x48656c6c6f417263686574797065 */
List
Concatenates two lists
of any element of any type.
It is equivalent to the following code:
var res : list<T> = l;
for e in reverse(L) do
res.prepend(e)
done;
L := res
For example:
const l = concat([1; 2; 3], [4; 5]);
/* l is [1; 2; 3; 4; 5] */
List of values
Concatenates values of a list, of type string
or bytes
For example:
const m = concat([ "Hello "; "Archetype "; "world!" ]);
/* m is "Hello Archetype world!"*/
Returns
contains(c : C, e : T)
e
is contained in c
or not.Parameters
Returns
contract_to_address(c : contract<T>)
Parameter
Returns
create_contract(handler, delegator, amount, init)
Creates an operation for contract origination. The returned operation is then to be added to the operations
builtin list of generated operations.
For example, in order to deploy a contract from Michelson source simple.tz
with natural 0
as initial storage:
archetype anothercontract
import simple from "simple.tz"
entry exec() {
const initial_storage : nat = 0;
const op_addr : (operation * address) =
create_contract(simple, none, 0tz, initial_storage);
operations := [op_addr[0]]
}
It is also possible to create a contract from an Archetype source.
Instead of passing the initial storage, a record of contract parameters is passed.
Say for example that the deployed contract declares a variable parameter named owner
typed address
:
archetype anothercontract
import "simple.arl"
entry exec() {
const op_addr : (operation * address) =
create_contract(simple, none, 0tz, { owner = caller });
operations := [op_addr[0]]
}
When the contract declares a constant parameter, then only a literal value can be passed. Say for example that the created contract has a constant parameter named total_amount
typed nat
:
archetype anothercontract
import "simple.arl"
entry exec() {
const op_addr : (operation * address) =
create_contract(simple, none, 0tz, { total_amount = 1_000_000 });
operations := [op_addr[0]]
}
Parameters
del
:
option<address>
init
:
any
- Record of parameters for Archetype contract
- Initial storage value for Michelson contrat
Returns
operation * address
- Operation for contract creation
- Address of created contract
create_ticket(s : T, n : nat)
E F
exec_lambda(f : lambda<T, R>, x : T)
Applies a lambda value f
to argument x
.
For example:
const plus_three = lambda((x : nat) -> x + 3);
const r = exec_lambda(plus_three, 1);
/* r is equal to 4 */
Parameters
x
:
T
Returns
exp_horner(v : rational, p : nat)
Horner's method applied to (the polynomial development of) the exponential function.
It is equivalent to the following archetype code:
function exp_horner(x : rational, precision : nat) : rational {
var r : rational = 1 + x / precision;
iter i to precision - 1 do
r := 1 + x * r / (precision - i)
done;
return r
}
Parameters
Returns
Fails with
does not fail
floor(r : rational)
Parameter
Returns
fold (i : or<L, R>, f : L -> or<L, R>)
fold
applies the inlined function f
to the left
of initial value i
:
- if it returns a
left
value, it appliesf
to the result off(i)
, and iteratively applies f on as long as it returns aleft
value. - if it returns a
right
value, iteration stops, and theright
value is returned.
Hence the application may be represented as:
fold(i, f) = right(f(...(f(i))))
For example, the following expression reverses the list l
typed list<nat>
:
var empty : list<nat> = [];
var p : or<list<nat> * list<nat>, list<nat>> = left<list<nat>> ((empty, l));
res := fold (p, x ->
match x[1] with
| hd::tail -> left<list<nat>> ((prepend(x[0], hd), tail))
| [] -> right<list<nat> * list<nat>>(x[0])
end
)
Folded function is inlined and cannot be a lambda
variable.
Parameters
f
:
function
- takes a parameter of type
L
- returns a values of type
or<L, R>
Returns
R
G H
get_denominator(r : rational)
get_entrypoint<T>(s, a : address)
Returns an option
of contract's entrypoint (typed contract<T>
) to the entrypoint s
with argument T
at contract address a
.
For example, consider the following contract at address a
:
archetype example
entry exec(n : nat) { /* ... */ }
The exec
entrypoint may be retrieved with:
const e = get_entrypoint("%exec", a) ? the : fail("EXEC_NOT_FOUND")
The entrypoint may then be used as an argument of make_operation
.
Parameters
s
:
string literal
%
Returns
option<contract<T>>
contract
value get_numerator(r : rational)
global_constant<T>(hash)
hash
. Check here the list of available global constants on mainnet.
Parameter
hash
:
expruQN5r2umbZVHy6WynYM8f71F8zS4AERz9bugF8UkPBEqrHLuU8
)Returns
Fails with
does not fail
greedy_and(a : bool, b : bool)
a
and b
, meaning that b
is evaluated even if a
is false.Parameters
Returns
greedy_or(a : bool, b : bool)
a
and b
, meaning that b
is evaluated even if a
is true.Parameters
Returns
head(l : list<T>, n : nat)
Returns the first n elements of list L
according to its order:
h0 := head([0; 1; 2], 2); /* h0 = [0; 1] */
If n
is greater than length(L)
, then the entire list is returned:
h1 := head([0; 1; 2], 4); /* h1 = [0; 1; 2] */
Parameters
Returns
I J
int_to_bytes(i : int)
Parameter
Returns
int_to_date(i : int)
i
to a date, where i
is considered as a tiemstamp value, that is the number of seconds since 1970-01-01
.Parameter
Returns
int_to_nat(i : int)
Parameter
Returns
option<nat>
some(n)
wheni
is positivenone
otherwise
is_implicit_address(a : address)
tz1
tz2
tz3
or tz4
, that is whether it is an implicit address.Parameter
Returns
Fails with
does not fail
is_none(o : option<T>)
Returns false
if an optional value o
is some
, true
otherwise.
It is equivalent to the following expression:
o ? false : true
or equivalently:
match o with
| some(v) -> false
| none -> true
end
Parameter
Returns
is_some(o : option<T>)
Returns true
if an optional value o
is some
, false
otherwise.
It is equivalent to the following expression:
o ? true : false
or equivalently:
match o with
| some(v) -> true
| none -> false
end
Parameter
Returns
join_tickets(t1 : ticket<T>, t2 : ticket<T>)
Parameters
Returns
option<ticket<T>>
K L
keccak(b : bytes)
key_hash_to_contract(pkh : key_hash)
Parameter
Returns
contract<unit>
key_to_address(k : key)
Parameter
Returns
key_to_key_hash(k : key)
Parameter
Returns
lambda_michelson<T, R>({ MICHELSON })
Builds a lambda expression from michelson code.
For example:
const size : lambda<string, nat> = lambda_michelson<string, nat>({SIZE});
Parameter
code
:
Michelson
T
and returns a value of type R
Returns
Fails with
does not fail
left<(L,)? T>(x : L)
Constructs a left value typed or<L, R>
.
The left type L
may be omitted as it can be inferred, but the right type R
is mandatory.
For example:
const o = left<string>(2)
o
is then typed option<nat, string>
. It is equivalent to:
const o = left<nat, string>(2)
Parameter
x
:
L
Returns
length(o : T)
Parameter
Returns
M N
make_asset(k : asset_key<A>, v : asset_value<A>)
Creates an asset from identifier and data (key and value).
It is typically convenient when an asset data is provided as an entry point parameter.
Consider for example the following asset declaration:
asset vehicle {
vin : string;
nbrepairs : nat = 0;
dateofrepair : date = now;
}
The add_vehicle
entry point below provides a vehicle data as a record:
entry add_vehicle(k : asset_key<vehicle>, d : asset_value<vehicle>) {
vehicle.put(make_asset(k, d))
}
Parameters
Returns
A
k
and data v
. make_big_map<K, V>(m)
This is useful to solve the type amiguity of literals, like for example the empty big_map
[]
.Parameter
Returns
Fails with
does not fail
make_event<T>(tag, v)
Makes an event operation.
For example:
const op : operation = make_event<nat>("%sample", 2);
operations := prepend(operations, op);
Parameters
Returns
make_map<K, V>(m)
This is useful to solve the type amiguity of literals, like for example the empty map
[]
.Parameter
Returns
Fails with
does not fail
make_list<T>(l)
This is useful to solve the type amiguity of literals, like for example the empty list
[]
.Parameter
Returns
Fails with
does not fail
make_operation(a : tez, c : contract<T>, arg : T)
Parameters
arg
:
T
Returns
make_sandbox_exec_operation(f : lambda<list<ticket<nat * option<bytes>>>, l : list<ticket<nat * option<bytes>>, a : tez)
f
lambda.Parameters
f
:
lambda<list<ticket<nat * option<bytes>>>
l
:
list<ticket<nat * option<bytes>>
f
Returns
Fails with
does not fail
make_set<T>(s)
This is useful to solve the type amiguity of literals, like for example the empty set
[]
.Parameter
Returns
Fails with
does not fail
map
Maps a value of type list<T>
, map<K, V>
, or option<T>
.
List
Applies an inlined function of type T -> T
on each element of a list of elements typed T
and returns a new list.
For example:
const l = map([ 1; 2 ; 3 ], x -> 2 * x + 1);
/* l is [ 3; 5; 7 ] */
Map
Applies an inlined function of type (K * V) -> V
on each value of a map with key of type K
and value of type V
; it returns a new map.
For example:
const m = map([ ("a", 5); ("b", 6); ("c", 7) ], x -> 2 * x[1] + 1)
/* m is [ ("a", 11); ("b", 13); ("c", 15) ] */
Note that the x
intput of the inlined mapping function is a pair (key and value) of the map; hence x[0]
is the key and x[1]
is the value.
Option
Applies an inlined function of type T -> T
to the some
value of an option<T>
value, or returns none
.
For example:
const o1 = map(some(2), x -> 2 * x + 1);
/* o1 is some(5) */
const o2 = map(none, x -> 2 * x + 1);
/* o2 is none */
Note that the ? :
syntax is also available to fold an option. The above example is then equivalent to:
const o1 = some(2) ? 2 * the + 1 : none;
/* o1 is some(5) */
Parameters
f
:
function
Returns
-
max(a : T, b : T)
a
and b
Parameters
Returns
michelson<R>({ MICHELSON }) [ STACK ]
Builds a value from Michelson instructions.
For example, the following michelson instructions return the sha3 value of the packed concatenation of a
and b
:
archetype michelson_expression
variable res : bytes = 0x
entry exec () {
const a = "Hello ";
const b = "Archetype!";
res := michelson<bytes> { CONCAT; PACK; SHA3 } [a : b]
}
Parameters
code
:
Michelson
args
:
Stack
Fails with
does not fail
min(a : T, b : T)
a
and b
Parameters
Returns
mutez_to_nat(v : tez)
Converts a tez
value in mutez (millionth of tez) to a nat
value.
For example:
const n = mutez_to_nat(5tz);
/* n is 5000000 */
Parameter
Returns
nat_to_bytes(n : nat)
Parameter
Returns
nat_to_string(n : nat)
Parameter
Returns
none<T>
none
value for type option<T>
.Returns
nth(l : list<T>, n : nat)
Returns an option of the n
th element of list l
.
Implementation is in O(n) complexity (Michelson lists are linked).
Parameters
Returns
O P
open_chest(k : chest_key, c : chest, t : nat)
c
with key k
under time t
.Parameters
Returns
option<bytes>
pack(o : T)
Parameter
Returns
pairing_check(l : list<bls12_381_g1 * bls12_381_g2>)
Parameter
l
:
list<bls12_381_g1 * bls12_381_g2>
Returns
prepend(l : list<T>, e : T)
e
at the beginning of list l
.Parameters
Returns
put(m : map<K, V>, k : K, v : V)
v
with key k
in map (map
, big_map
or iterable_map
)m
.Parameters
Returns
Q R
read_ticket(t : ticket<T>)
Parameter
Returns
address * T * nat
remove(c : C, i : T)
c
without item i
.Parameters
i
:
T
Returns
reverse(l : list<T>)
l
with elements in reverse order.Parameter
Returns
right<T(, R)>(x : R)
Constructs a right value typed or<L, R>
.
The left type L
is mandatory, while the right type R
may be omited as it can be inferred.
For example:
const o = right<nat>("abc")
o
is then typed option<nat, string>
. It is equivalent to:
const o = right<nat, string>("abc")
Parameter
x
:
R
Returns
S T
sapling_empty_state(k : key_hash)
Parameter
Returns
sapling_verify_update(s, t)
Parameters
Returns
option<bytes * int * sapling_state(n)>
set_delegate(opkh : option<key_hash>)
Parameter
opkh
:
none
remove delegation of current contractsome(pkh)
update delegation of current contract with address behindpkh
Returns
sha256(b : bytes)
Parameter
Returns
sha3(b : bytes)
sha512(b : bytes)
Parameter
Returns
simplify_rational(r : rational)
Parameter
Returns
slice(s : T, o : nat, l : nat)
Extracts a section of a string or bytes s
and returns it as a new string or bytes.
The section starts at offset postion o
is has a length of l
.
For example:
const s = "Hello Archetype World!";
const e = slice(s, 6, 9) ? the : ""; /* e is "Archetype" */
const b = 0x48656c6c6f2041726368657479706520576f726c64;
const c = slice(b, 12, 18); /* c is some(0x417263686574797065) */
const f = slice(b, 30, 40); /* f is none */
Parameters
Returns
none
if a problem occured (offset + length out of bounds)some(v)
,v
being the value of sub sequence
some(v : T)
some
value for type option<T>
.Parameter
Returns
split_ticket(t : ticket<T>, n1 : nat, n2 : nat)
Parameters
Returns
option<ticket<T> * ticket<T>>
n1
and n2
values. sub_mutez(a : tez, b : tez)
a
to b
and returns an option of tez value.Parameters
Returns
sub_nat(a : nat, b : nat)
a
to b
and returns an option of nat value.Parameters
Returns
option<nat>
some
ofa - b
whena >= b
none
otherwise
T U
tail(l : list<T>, n : nat)
Returns the last n elements of list L
according to its order:
t0 := tail([0; 1; 2], 2); /* t0 = [1; 2] */
If n
is greater than length(L)
, then the entire list is returned:
t1 := tail([0; 1; 2], 4); /* t1 = [0; 1; 2] */
Parameters
Returns
unpack<T>(b : bytes)
Deserializes a value of type bytes
into the corresponding value of type option<T>
.
For example, suppose p
is a bytes value:
const v ?= unpack<nat>(p) : "UNPACK_FAILED";
/* v is typed nat */
Parameter
Returns
update(m : map<K, V>, k : K, v : option<T>)
v
from associated to key k
in map m
: none
removes keyk
some(v)
, adds keyk
with valuev
Parameters
k
:
K
Returns
update(s : set<T>, e : T, b : bool)
e
in set s
: - removes
e
whenb
isfalse
- adds
e
whenb
istrue
Parameters
e
:
T