Tezos
val get_balance : unit -> tez
let get_balance: (_u: unit) => tez
Get the balance for the contract.
let check (p,s : unit * tez) = [], Tezos.get_balance()
let check = (p: unit, s: tez):[list<operation>, tez] =>
[list([]), Tezos.get_balance()];
val get_now : unit -> timestamp
let get_now: (_u : unit) => timestamp
Returns the current time as a UNIX timestamp.
In LIGO, timestamps are type compatible in operations with integers. This lets you set for instance time constraints for your smart contracts like this:
Examples
24 hours from now
let today = Tezos.get_now ()
let one_day = 86_400
let in_24_hrs = today + one_day
let some_date = ("2000-01-01t10:10:10Z" : timestamp)
let one_day_later = some_date + one_day
let today = Tezos.get_now();
let one_day = 86_400;
let in_24_hrs = today + one_day;
let some_date = ("2000-01-01t10:10:10Z" as timestamp);
let one_day_later = some_date + one_day;
24 hours ago
let today = Tezos.get_now ()
let one_day = 86_400
let in_24_hrs = today - one_day
let today = Tezos.get_now();
let one_day = 86_400;
let in_24_hrs = today - one_day;
Comparing Timestamps
You can also compare timestamps using the same comparison operators as for numbers
let not_tomorrow = (Tezos.get_now () = in_24_hrs)
let not_tomorrow = (Tezos.get_now() == in_24_hrs);
val get_amount : unit -> tez
let get_amount: (_u : unit) => tez
Get the amount of tez provided by the sender to complete this transaction.
let threshold (p : unit) = if Tezos.get_amount () = 100tz then 42 else 0
function threshold (p : unit) {
if (Tezos.get_amount() == 100tez) return 42 else return 0;
};
val get_sender : unit -> address
let get_sender: (_u : unit) => address
Get the address that initiated the current transaction.
let check (p : unit) = Tezos.get_sender ()
let check = (p : unit) => Tezos.get_sender ();
val address : 'a contract -> address
let address: (contract: contract<'a>) => address
Get the address associated with a value of type contract
.
let check (p : key_hash) =
let c = Tezos.implicit_account p
in Tezos.address c
let check = (p : key_hash) => {
let c = Tezos.implicit_account(p);
return Tezos.address(c);
};
val get_self_address : unit -> address
let get_self_address: (_u : unit) => address
Get the address of the currently running contract.
let check (p : unit) = Tezos.get_self_address ()
let check = (p : unit) => Tezos.get_self_address();
val self : string -> 'a contract
let self: (entrypoint: string) => contract<'a>
Typecast the currently running contract with an entrypoint annotation. If you are using entrypoints, use "%bar" for a constructor "Bar". If you are not using entrypoints: use "%default"
let check (p : unit) = Tezos.self("%default")
let check = (p: unit) => Tezos.self("%default");
val implicit_account : key_hash -> 'a contract
let implicit_account : (_: key_hash) => contract<unit>
Get the default contract associated with an on-chain key-pair. This contract does not execute code, instead it exists to receive tokens on behalf of a key's owner.
See also: http://tezos.gitlab.io/user/glossary.html#implicit-account
let check (kh : key_hash) = Tezos.implicit_account kh
let check = (kh: key_hash) => Tezos.implicit_account(kh);
val get_source : unit -> address
let get_source: (_u : unit) => address
Get the originator (address) of the current transaction. That is, if
a chain of transactions led to the current execution get the address
that began the chain. Not to be confused with Tezos.get_sender
, which
gives the address of the contract or user which directly caused the
current transaction.