TS Types
This section presents types and functions exported by the @completium/archetype-ts-types
package and used by contracts' bindings interface (storage, entry points, views).
A B
Address
Class for an address value that corresponds to Archetype/Michelson type address
. Its contructor takes a string address value.
For example:
const a = new Address("tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb")
Fails with
"No matching prefix found."
tz1
, tz2
, tz3
, tz4
, KT1
"The decoded output is the wrong length for the given prefix."
Methods
annotated_mich_to_array(x, t)
Pair
nodes.Parameters
Returns
Array<Micheline>
Pair
's leafsFails with
Found an unannotated node that is not a pair
Pair
's leaf is not annotatedBls12_381_fr
Class for value that corresponds to Archetype/Michelson type bls12_381_fr
. Its constructor takes a string value.
For example:
const bls_fr = new Bls12_381_fr("0x063bd6e11e2fcaac1dd8cf68c6b1925a73c3c583e298ed37c41c3715115cf96358a42dbe85a0228cbfd8a6c8a8c54cd015b5ae2860d1cc47f84698d951f14d9448d03f04df2ca0ffe609a2067d6f1a892163a5e05e541279134cae52b1f23c6b")
Methods
toString
string
representationfrom_mich
Bls12_381_fr
value from the Micheline
argumentBls12_381_g1
Class for value that corresponds to Archetype/Michelson type bls12_381_g1
. Its constructor takes a string value.
For example:
const bls_g1 = new Bls12_381_g1("0x063bd6e11e2fcaac1dd8cf68c6b1925a73c3c583e298ed37c41c3715115cf96358a42dbe85a0228cbfd8a6c8a8c54cd015b5ae2860d1cc47f84698d951f14d9448d03f04df2ca0ffe609a2067d6f1a892163a5e05e541279134cae52b1f23c6b")
Methods
toString
string
representationfrom_mich
Bls12_381_g1
value from the Micheline
argumentBls12_381_g2
Class for value that corresponds to Archetype/Michelson type bls12_381_g2
. Its constructor takes a string value.
For example:
const bls_g2 = new Bls12_381_g2("0x063bd6e11e2fcaac1dd8cf68c6b1925a73c3c583e298ed37c41c3715115cf96358a42dbe85a0228cbfd8a6c8a8c54cd015b5ae2860d1cc47f84698d951f14d9448d03f04df2ca0ffe609a2067d6f1a892163a5e05e541279134cae52b1f23c6b")
Methods
toString
string
representationfrom_mich
Bls12_381_g2
value from the Micheline
argumentBytes
Class for a bytes value that corresponds to Archetype/Michelson type bytes
. Its constructor takes a string value.
For example:
const bls_g2 = new Bytes("0x050002")
Methods
toString
string
representationhex_encode
hex_decode
bool_to_mich(v)
boolean
value to Micheline.Parameter
v
:
boolean
Returns
Fails with
does not fail
C D
Chain_id
Class for a chain id value that corresponds to Archetype/Michelson type chain_id
. Its constructor takes a string value.
For example:
const cid = new Chain_id("NetXdQprcVkpaWU")
Fails with
"No matching prefix found."
Net
"The decoded output is the wrong length for the given prefix."
Methods
CallParameter
Chest
Class for a chest value that corresponds to Archetype/Michelson type chest
. Its constructor takes a string value.
For example:
const c = new Chest("0xc5ecdde89eb8c1e7aaeb85abb8f5e5cef3b4fa80c4aee2fccbf0a78ce0debaa5e9ddede3ddfbd9abdea28cc7dc99e6d3a9baf3cbae9adaaabc89cbc39e97e2c7a6cba99197d19ba09ddfd181afc997ffbcc5acb2d29ecbb698c2cacbdd83d1b4ced0bffe9cd78295b3fba4d9f9d5f4d4ec9ad3c7e1a8eeb9dba5cbd8a2dbf29af8e4a4c1e4b1edacf98fccefaef9fea4f0bacdd38ecbfe81c3f9839b9e9ab8fbf5f1eabac48a9f8ca7c588eefe94d1f18bd9bcee9aecde8dd285cf9098f4e1a7eec787f3a0e0ff9cd0ce8ec5a2a4e5ecb08fce899eb5baa397fabf90de9397cebc81bbdfb386e6b4da9fd8fdd19ed9f8d684c782b0aacfeebae4f6e7d1c5c1e6a093c68081cf83b991b4ecd7b38aee92deddcad79eb9abe0a0a0c6b5909dc58495f69445fff5ae9cefe8b8beb2fb86ccf5c9ad91989bdad8a3cfbedaffa2de8bf19dc6ac8cbc8a9584fa9f85f9ba958fc6bbc09ac8e7d5f0fdb98b86c1c7d59ad7c6dfc2d2cefaf5d9db909bf0e3acd3ccc792bc9bccbab4a4febda9b685dbc39ea2a4a7b69990d3abd8b9b3d7dbc581b984f3e08a98f7f7f0e697cc8dfd88edc8c3ca8dc3b2a9ccf6cdd6d0efcc848bc8ead5858bbabfcfc1c8ecea84fd9b96a5e4eabb8c918dafe6f78d83e8e1c2e5f8ee88a4ee8dcaeeafffebfcbbfda1e9eb86c582f2eedd9299cbc0a7fce083ced8c8ddb0e7eaacb696c1fccdadcdc8e3c6f7b9de84eece9bb7919094fef4fdf6efd8b1ba8bbecb9380add4f59ddbf9a19f95facc84e9d0a99bfa93f1fcc3a0fbde9b9ce0c7e8dec6e8d1dfa7dda6f490bb9580abfdbcc0e202e5ff731c3c17d080ee430edd30979a47aa653656e11e593800000015c2ca2a23b732a72932611618ad9ea324986377591e")
Methods
Chest_key
Class for a chest key value that corresponds to Archetype/Michelson type chest_key
. Its constructor takes a string value.
For example:
const c = new Chest_key("0xa0aceddfb3c9fbe1b8c382c7d5a7dedbe2e5adf9edcfc3e9d084caa6aeb9818ff1e985cb9efe8fa089ceeaa0f5d0bcb583e2f29196f2d3908fffffdcda868faffcb78fb697e7eaf3e7dca9d4b5dda2c3e4f8adf8abf484ecae85f7d6e0f2d28cb69af1d7b19082e8d8d7ba96e7e1e0bb8ac9b9fcf0a9e5b7c1a499c4faf4c8a3a9c8e4d09aa780eac6cee1b78a97a3e983abf9a5f1e8d2a2a2b5e3bcb8c4effeb7a3a68a85a497cd91c9a2c096c3f596deb8d1aca3a5aff28effb8cfc9c7ced892e3a7c09deeb8c8ec9387a3b384b5c8bccaafc7a9a2c1cfd8c7becfd7d6828a9af8f4988fe4ead3b59ecfb8ff8cabf8be90d4c8bdbddfce9cd7c2bb81edc4b7ad80a59a978f8c9debe7aaf08cf0c588f3eaade6b9f4e4e6edf1ed9c9988e48d9ba0aa8f01d18bac92b886db9dd798b5f6fdc891a28da2c4c48da1918897a2b7c2dfa0b78ab8e291b68fb1a2bfa5e8b88e9cabb0b5b0feabcffc9cfeee888ac4afeed9dc8bf5a4eaa9ae89a3838cf6cfd4f8acff8fa7aef7a9889fbbc7d8f6dde4edf3e58096e580e299e5b082b9cf85f3fe8ac6c0998eb1bcbab9bfb8fba39faea7bce0f6fed9ea86dfdad58cf7cbc7fcc4ecf7e2e898d3b19582e38c8092b7e4a0cddc83eb8bc38d91fefed6be869496b8e4fc99d5fae5c6a2b2dcabe2a4ea85b68b87b182d7e8cac29fe0b9efd6d0eb999ffa98aaaf9bf09fe7c4b39d81db97e4e7bbaef0e3bfedd69d9089bc8d91b292afa6c8b389fc9fb7aaa8decab6d9b493a6eafaa5baffe8fb85f2d483ecd1f2d1e58f938df9d8d5e385fe96c5f58ae1e0b09bf2b3c2931f")
Methods
date_cmp(a, b)
Parameters
a
:
Date
b
:
Date
Returns
boolean
true
if a
equals b
(without milliseconds).Fails with
does not fail
date_to_mich(v)
Parameter
v
:
Date
Returns
Fails with
does not fail
Duration
Class for a duration value that corresponds to Archetype type duration
. Its constructor takes a string value that is the Archetype literal.
For example, a duration of 10 seconds:
const d1 = new Duration("10s") // 10 seconds
A duration of 5 minutes:
const d2 = new Duration("5m") // 5 minutes
A duration of 18 hours:
const d3 = new Duration("18h") // 18 hours
A duration of one week:
const d4 = new Duration("1w") // 1 week
A duration of 5 minutes and 10 seconds:
const d5 = new Duration("5m10s")
A duration of 3 weeks, 8 days, 4 hours, 34 minutes and 18 seconds:
const d6 = new Duration("3w8d4h34m18s")
Fails with
"Invalid duration input"
Methods
E F
elt_to_mich(a, b)
Elt
node.Parameters
Returns
Fails with
does not fail
Entrypoint
Class for entry point value that corresponds to Archetype/Michelson type contract
. Its constructor takes the contract's Address
value and the entry point name as string
.
For example:
const e = new Entrpoint(new Address("KT1QJSgFHZYsP8V8snXKmoKTqq2dDfTE626p"), "exec")
Methods
Enum
Abstract class from which binding's generated enum
classes are derived. Its constructor takes the name of the enum as a string.
See here for an example.
Methods
toString
string
representationtype
I J
Int
Class for integer value that corresponds to Archetype/Michelson type int
. It uses the bignumber.js package to support the arbitrary-precision feature of Tezos.
There are several ways to construct an Int
value:
From number
:
const i = new Int(-3)
From string
:
const i = new Int("0987654323456789876543456789876543456789876543456789876543")
From bignumber
:
const bn = new BigNumber("0987654323456789876543456789876543456789876543456789876543")
const i = new Int(bn)
Fails with
Not an Int value
when the constructor parameter does not represent a integer value
Methods
toString
string
representationto_big_number
bignumber.js
valueto_number
number
value. It is approximated if this
is over number
representation capacity.is_left(v)
v
is a Left
node.Parameter
v
:
Micheline
Returns
boolean
true
if and only if v
is Left
Fails with
does not fail
is_right(v)
v
is a Right
node.Parameter
Returns
boolean
true
if and only if v
is Right
Fails with
does not fail
K L
Key
Class for key value that corresponds to Archetype/Michelson type key
. Its constructor takes a string value.
For example:
const k = new Key("edpkurLzuFFL1XyP3fed4u7MsgeywQoQmHM45Bz91PBzDvUjQ9bvdn")
Fails with
"No matching prefix found."
edpk
, sppk
, p2pk
"The decoded output is the wrong length for the given prefix."
Methods
Key_hash
Class for key hash value that corresponds to Archetype/Michelson type key_hash
. Its constructor takes a string value.
For example:
const k = new Key_hash("tz1Lc2qBKEWCBeDU8npG6zCeCqpmaegRi6Jg")
Fails with
"No matching prefix found."
tz1
, tz2
, tz3
, tz4
, KT1
"The decoded output is the wrong length for the given prefix."
Methods
left_to_mich(v)
Left
value.Parameter
v
:
Micheline
Left
valueReturns
Fails with
does not fail
list_to_mich(l, toMich)
toMich
to elements in l
Parameters
l
:
Array<T>
toMich
:
{ (a: T): Micheline }
l
Returns
Array<Micheline>
Fails with
does not fail
list_annots_to_mich_type(mt, annots)
list
of elements of type mt
Parameters
annots
:
Array<string>
Returns
Fails with
does not fail
list_to_mich_type(mt)
list
of elements of type mt
Parameter
Returns
Fails with
does not fail
M N
mich_array_to_mich(l)
l
Parameter
l
:
Micheline[]
Returns
Fails with
does not fail
mich_to_bool(x)
boolean
valueParameter
Returns
boolean
true
if x
's prim is True
, false
if False
Fails with
"Invalid prim"
x
's prim is not True
nor false
mich_to_date(x)
Date
valueParameter
Returns
Date
Date
valueFails with
Error
x
's prim does not represent a datemich_to_map(l, f)
f
to Micheline Melt
values of Marray
x
Parameters
f
:
(k: Micheline, v: Micheline): [K, V]
Returns
Array<[K, V]>
Micheline
Micheline refers here to the JSON format of a Michelson literal. It is in fine the format used to interact with the Tezos blockchain: entry point parameters, contract storage and so on, are exchanged in Micheline format.
The goal of the contract binding is to provide a native TypeScript interface that translates to Micheline values. Hence in most cases, thanks to contract binding, you should not deal with Micheline values.
The type provided here is a full-featured Typescript implementation of a Micheline value, such that a Micheline-typed value is ensured to be a valid Micheline value.
MichelineType
Micheline type refers here to the JSON format of a Michelson literal's type.
The type provided here is a full-featured Typescript implementation of a Micheline type value, such that a MichelineType-typed value is ensured to be a valid Micheline type value.
Nat
Class for natural value that corresponds to Archetype type nat
. It uses the bignumber.js package to support the arbitrary-precision feature of Tezos.
There are several ways to construct an Nat
value:
From number
:
const n = new Int(42)
From string
:
const n = new Int("0987654323456789876543456789876543456789876543456789876543")
From bignumber
:
const bn = new BigNumber("0987654323456789876543456789876543456789876543456789876543")
const n = new Int(bn)
Fails with
Not a Nat value
when the constructor parameter does not represent a natural value
Methods
toString
string
representationto_big_number
bignumber.js
valueto_number
number
value. It is approximated if this
is over number
representation capacity.O P
Option
Generic class for an optional value that corresponds to Archetype/Michelson type option
. The class is parameterized with the type of the optional value. Its constructor takes the optional value, null
or undefined
.
For example, an optional natural value:
const o1 = new Option<Int>(new Nat(42))
An optional string, using the Some
static method:
const o2 = new Option.Some<string>("Hello Option!")
A none
value of Int
, using the None
static method:
const o3 = new Option.None<Int>() // typed Option<Int>
Methods
toString
string
representationSome
none
option.None
some
option of its argument.get
is_some
returns true
, null
otherwise.is_some
true
if get
does not return null
, false
otherwise.is_none
true
if get
does return null
, false
otherwise.option_annot_to_mich_type(a, annots)
option
Micheline type of a
Parameters
annots
:
string[]
Returns
Fails with
does not fail
option_to_mich_type(a)
option
Micheline type of a
Parameter
Returns
Fails with
does not fail
Or
Generic class for value that corresponds to the Archetype/Micheline type or
. The class is parameterized with left and right types. Its constructor takes an argument of type left or right and a boolean that is true
if this is a left value.
Static methods Left
and Right
are rather used to make an Or
value. For example:
const l = Or.Left<Nat, string>(new Nat(2))
To make a right value:
const r = Or.Right<Nat, string>("Hello Or!")
Methods
toString
string
representationfrom_mich
Or
value. Its arguments are:- a
Micheline
value - a
mich_to_left
function that returns a left typed value - a
mich_to_right
function that returns a right typed value
to_mich
Left
Or
value from a left typed valueRight
Or
value from a right typed valueget
is_left
true
if this is an Or
of left value, false
otherwiseis_right
true
if this is an Or
of right value, false
otherwiseor_to_mich_type(l, r, a)
or
Micheline type of l
and r
Parameters
Returns
Fails with
does not fail
pair_to_mich(l)
or
Micheline type of l
and r
Parameters
Returns
Fails with
does not fail
pair_annot_to_mich_type(p, a, b, annots)
p
and arguments a
and b
Parameters
p
:
string
"big_map"
"lambda"
"or"
annots
:
string[]
Returns
Fails with
does not fail
pair_array_to_mich_type(l, annots)
pair
Micheline type of types l
Parameters
l
:
MichelineType[]
annots
:
string[]
Returns
Fails with
does not fail
pair_to_mich_type(p, a, b)
p
and arguments a
and b
Parameters
p
:
string
"big_map"
"lambda"
"or"
Returns
Fails with
does not fail
prim_annot_to_mich_type(p, a)
Parameters
p
:
string
"address"
"bls12_381_fr"
"bls12_381_g1"
"bls12_381_g2"
"bool"
"bytes"
"chain_id"
"chest"
"chest_key"
"int"
"key"
"key_hash"
"mutez"
"nat"
"never"
"operation"
"signature"
"string"
"timestamp"
"unit"
)a
:
string[]
Returns
Fails with
does not fail
prim_to_mich_type(p)
Parameter
p
:
string
"address"
"bls12_381_fr"
"bls12_381_g1"
"bls12_381_g2"
"bool"
"bytes"
"chain_id"
"chest"
"chest_key"
"int"
"key"
"key_hash"
"mutez"
"nat"
"never"
"operation"
"signature"
"string"
"timestamp"
"unit"
)Returns
Q R
Rational
Class for a rational value that corresponds to the Archetype type rational
. Its constructor takes an argument of type number
, string
or bignumber
for aritrary precision arithmetic.
There are several ways to construct an Rational
value:
From number
:
const r = new Rational(-3.6)
From string
:
const r = new Int("98.7654323456789876543456789876543456789876543456789876543")
From bignumber
:
const bn = new BigNumber("98.7654323456789876543456789876543456789876543456789876543")
const r = new Rational(bn)
From two bignumber
values (numerator and denominator):
const n = new BigNumber("567")
const d = new BigNumber("37")
const r = new Rational(n, d)
Fails with
"Rational error"
string
value is not a numberMethods
toString
string
representationto_big_number
bignumber.js
valueto_number
number
value. It is approximated if this
is over number
representation capacity.div
ceil
Int
ceiled value.right_to_mich(v)
Right
value.Parameter
v
:
Micheline
Right
valueReturns
Fails with
does not fail
S T
Sapling_state
Class for a sapling state value that corresponds to Archetype/Michelson type sapling_state
. Its constructor takes a string value.
Methods
toString
string
representationfrom_mich
Sapling_state
value from the Micheline
argumentSapling_transaction
Class for a sapling transaction value that corresponds to Archetype/Michelson type sapling_transaction
. Its constructor takes a string value.
Methods
toString
string
representationequals
from_mich
Sapling_transaction
value from the Micheline
argumentset_annot_to_mich_type(mt, annots)
set
of elements of type mt
Parameters
annots
:
string[]
Returns
Fails with
does not fail
set_to_mich_type(mt)
set
of elements of type mt
Parameter
Returns
Fails with
does not fail
Signature
Class for a signature value that corresponds to Archetype/Michelson type signature
. Its constructor takes a string value.
For example:
const s = new Signature("edsigtvwtJaiM7phNNkZjazqKtthDxc3WswYNL961GKgz7VxvPJmWJ8WEkmEZd9oFM1RvwABYW3uYgwGRP7nuBns5WrqyfYsUaB")
Methods
string_cmp(a, b)
Parameters
a
:
string
b
:
string
Returns
boolean
true
if a
equals b
Fails with
does not fail
Tez
Class for a tez value that corresponds to Archetype type tez
and Michelson type mutez
. Its constructor takes a value of type string
, number
or bignumber
, and an optional string value for unit that is either "tez"
or "mutez"
(defaulted to "tez"
when not specified).
For example, five tez:
const amount = new Tez(5)
Again five tez from mutez value:
const amount = new Tez("5000000", "mutez")
Fails with
"Invalid Tez value"
string
value is not a numberMethods
toString
string
representationto_big_number
bignumber.js
valueTicket
Class for a ticket value that corresponds to Archetype/Michelson type ticket
. Its constructor takes a string value.
Methods
ticket_annots_to_mich_type(mt, annots)
ticket
Micheline type of element of type mt
Parameters
annots
:
string[]
Returns
MichelineType
ticket
Micheline typeFails with
does not fail
ticket_to_mich_type(mt)
ticket
Micheline type of element of type mt
Parameter
Returns
MichelineType
ticket
Micheline typeFails with
does not fail
U V
Unit
Class for a unit value that corresponds to Archetype/Michelson type unit
.
Methods