Basic Types
fi is a statically typed language, where a variable must be typed on declaration and that type cannot change. When you are setting a variable to a literal value, you must also ensure the type is declared.
1
storage nat Foo;
2
3
entry Test(int Bar){
4
let string Hello = string "World";
5
#We must declare the type of all literals
6
}
Copied!
During compilation, types are strictly checked and enforced. These types reflect the native Michelson types. All available basic types are defined below:

Boolean

bool - possible values being either true or false.
1
let bool available = bool true;
Copied!

Integers & Natural Numbers

Integers and naturals are arbitrary-precision, meaning the only size limit is fuel. The only difference is that Natural Numbers are unsigned.
int - possible values being any integer value (negative and positive) nat - possible values being any positive integer value
1
let nat n1 = nat 1;
2
let nat n2 = nat 2;
3
let nat n3 = sub(n1, n2); # Fail - must be declared as an int
4
let int n4 = sub(n1, n2); # OK
5
let nat n5 = to_int(sub(n1, n2)); # Also OK
Copied!
Note: Some arithmetic functions will return a different type based on the input types. You can use to_* functions if you need to typecast a specific value.

Strings

Strings are used to hold a value in text form.
string - possible value being anything, but must be encompassed by double-quotes "text"
1
let string name = string "John";
Copied!

Mutez

Mutez is the native Michelson type for defining a variable to represent a mutez, the native currency of Tezos in its smallest denomination (e.g. 0.000001 tez).
Mutez are internally represented by a 64 bit signed integer. There are restrictions to prevent creating a negative amount of mutez. Operations are limited to prevent overflow and mixing them with other numerical types by mistake. They are also checked for under/overflows.
mutez - possible values being any positive integer value
1
let mutez amount = mutez 100000000;
Copied!

Timestamp

Timestamps represent a date/time value.
timestamp - valid RFC 339 notation, encompassed by double-quotes, or alternatively number of seconds since Unix Epoch.
1
let timestamp today = timestamp "2019-02-20 00:00:00";
2
let timestamp alsotoday = timestamp 1550638795;
Copied!

Address

Addresses are untyped native contract addresses stored on the Tezos blockchain.
address - must be a valid public address and must be provided in the base58-check encoded version encompassed by double quotes (e.g. "KT1...", "tz1...").
1
let address payee = address "tz1...";
Copied!

Public Key

Public keys are used for verifying a signed message using the verify function, or can be converted to a public key hash (pkh/key_hash) and used for on-chain operations (delegation, origination and transfer).
key - must be a valid public key, encompassed by double quotes, in the base58-check encoded format (e.g. "edpk...", "p2pk")
1
let key signer = key "edpk...";
Copied!

Public Key Hash

Public key hashes are the hashed form of a key, and can also be used to create an implicit contract (and therefore address using typecasting). This type can be declared as key_hash or via an alias, pkh.
key_hash|pkh - must be a valid public key hash, encompassed by double quotes, in the base58-check encoded format (e.g. "tz1...", "tz2...").
1
let key_hash signer = pkh "tz1...";
Copied!

Signature

Signatures are base58-check encoded signatures (e.g. "edsig..."). These can be generated by the node-client to sign a message with a users private key. This can then be verified within fi using the verify function.
signature - must be a valid base58-check encoded signature, encompassed by double-quotes "..."
1
let signature sig = signature "edsig...";
Copied!

Bytes

Bytes are defined as hexadecimal, and can be used for multiple purposes.
bytes - must be valid hex, starting with 0x. This should not be wrapped in double quotes;
1
let bytes b = bytes 0x08aa28;
Copied!
Last modified 2yr ago