Skip to main content
Version: 1.4.0

Timestamps, Addresses

Timestamps

LIGO features timestamps, as Michelson does, while bakers baking the block (including the transaction in a block) are responsible for providing the given current timestamp for the contract.

Starting time of the current block

You can obtain the starting time of the current block using the built-in Mavryk.get_now. This timestamp does not change during the execution of the contract. Please be aware that it is up to the baker to set the current timestamp value.

const today: timestamp = Mavryk.get_now();

When running code, the LIGO CLI option --now allows you to control what Mavryk.get_now returns.

Timestamp Arithmetics

In LIGO, timestamps can be added to integers, allowing you to set time constraints on your smart contracts. Consider the following scenarios.

In 24 hours

const today: timestamp = Mavryk.get_now();
const one_day: int = 86_400;
const in_24_hrs: timestamp = today + one_day;
const some_date: timestamp = "2000-01-01t10:10:10Z" as timestamp;
const one_day_later: timestamp = some_date + one_day;

24 hours Ago

const today: timestamp = Mavryk.get_now();
const one_day: int = 86400;
const in_24_hrs: timestamp = today - one_day;

Subtracting timestamps

Timestamps can be subtracted, that means, we can use minus (-) between two timestamps:

const today: timestamp = Mavryk.get_now();
const some_date: timestamp = "2035-01-01t10:10:10Z" as timestamp;
const secs_until_some_date: int = some_date - today;

Notice that the result of such subtraction is an int, which describes the difference in seconds between the two timestamps.

Comparing Timestamps

You can compare timestamps using the same comparison operators applying to numbers.

const not_tomorrow: bool = (Mavryk.get_now() == in_24_hrs);

Addresses

The address type in LIGO denotes Mavryk addresses (mv1, mv2, mv3, KT1, ...). Currently, addresses are created by casting a string to the address type. Beware of failures if the address is invalid. Consider the following examples.

const my_account: address =
"mv18Cw7psUrAAPBpXYd9CtCpHg9EgjHP9KTe" as address;

Signatures

The signature type in LIGO datatype is used for Mavryk signatures (edsig, spsig). Signatures are created by casting a string. Beware of failure if the signature is invalid.

Here is how you can define a signature:

const my_sig: signature =
"edsigthTzJ8X7MPmNeEwybRAvdxS1pupqcM5Mk4uCuyZAe7uEk68YpuGDeViW8wSXMrCi5CwoNgqs8V2w8ayB5dMJzrYCHhD8C7" as
signature;

Keys

The key type in LIGO is used for Mavryk public keys. Do not confuse them with map keys. Keys are made by casting strings. Beware of failure if the key is invalid.

Here is how you can define a key.

const my_key : key =
"edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" as key;