Tezos
function balance : tez
Get the balance for the contract.
Note that
balance
andCurrent.balance
are deprecated.
function now : 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 nowNote that
now
is deprecated. Please useTezos.now
.
#
24 hours agoNote that
now
is deprecated. Please useTezos.now
.
#
Comparing TimestampsYou can also compare timestamps using the same comparison operators as for numbers
Note that
now
is deprecated. Please useTezos.now
.
function amount : tez
Get the amount of tez provided by the sender to complete this transaction.
Note that
amount
is deprecated.
function sender : address
Get the address that initiated the current transaction.
Note that
sender
is deprecated. Please useTezos.sender
.
function address : contract 'a -> address
Get the address associated with a value of type contract
.
Note that
implicit_account
andaddress
are deprecated. Please useTezos.implicit_account
andTezos.address
instead.
function self_address : address
Get the address of the currently running contract.
Note that
self_address
is deprecated. Please useTezos.self_address
.
function self : string -> contract 'a
Typecast the currently running contract with an entrypoint annotation. If your are using entrypoints: use "%bar" for constructor Bar If you are not using entrypoints: use "%default"
function implicit_account : key_hash -> contract 'a
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
Note that
implicit_account
is deprecated. Please useTezos.implicit_account
.
function source : 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.sender
, which
gives the address of the contract or user which directly caused the
current transaction.
⚠️ There are a few caveats you should keep in mind before using
Tezos.source
overTezos.sender
:
Tezos.source
will never be a contract, so if you want to allow contracts (multisigs etc) to operate your contract, you need to useTezos.sender
- https://vessenes.com/tx-origin-and-ethereum-oh-my/ -- in general it is somewhat unsafe to assume that
Tezos.source
understands everything that is going to happen in a transaction. IfTezos.source
transfers to a malicious (or sufficiently attackable) contract, that contract might potentially transfer to yours, withoutTezos.source
's consent. So if you are usingTezos.source
for authentication, you risk being confused. A good historical example of this is bakers paying out delegation rewards. Naive bakers did (and probably still do) just use tezos-client to transfer to whatever KT1 delegates they had, even if those KT1 were malicious scripts.
Note that
source
is deprecated. Please useTezos.source
.
function failwith : 'a -> unit
function chain_id : chain_id
Get the identifier of the chain to distinguish between main and test chains.
This is mainly intended to avoid replay attacks between the chains, and can currently
only be used together with Bytes.pack
and Bytes.unpack
.
function transaction : 'parameter -> mutez -> contract('parameter) -> operation
Transfer tez
to an account, or run code of another smart contract.
To indicate an account, use unit
as parameter
.
function set_delegate : option(key_hash) -> operation
Modify the delegate of the current contract.
The operation fails when:
- the delegate is the same as current delegate
- the keyhash is not of a registered delegate
Use None
to withdraw the current delegate.
function get_contract_opt : address -> option(contract('parameter))
Get a contract from an address.
When no contract is found or the contract doesn't match the type,
None
is returned.
function get_entrypoint_opt : string -> address -> option(contract('parameter))
Get a contract from an address and entrypoint.
Entrypoints are written in the form of: %entrypoint
.
When no contract is found or the contract doesn't match the type,
None
is returned.
function pairing_check : list(bls12_381_g1 * bls12_381_g2) -> bool
Verify that the product of pairings of the given list of points is equal to 1 in Fq12. Returns true if the list is empty.
Can be used to verify if two pairings P1 and P2 are equal by verifying P1 * P2^(-1) = 1
.
(extracted from Tezos documentation)
Sapling
Delphi protocol introduced the following sapling types (state and transaction) with N being an int singleton
function sapling_empty_state : sapling_state (N)
Sapling empty state
function sapling_verify_update : sapling_transaction (N) -> sapling_state (N) -> option (int * sapling_state (N))
Verify sapling update
Tickets
function create_ticket : 'value -> nat -> ticket ('value)
To create a ticket, the value and the amount of tickets to be created needs to be provided.
The ticket will also contain the contract address it originated from (which corresponds to Tezos.self
).
function read_ticket : ticket ('value) -> (address * ('value * nat)) * ticket ('value)
Reading a ticket will return a tuple with the ticket address, the value and the same ticket for later use.
A ticket is only consumed when it is dropped (e.g. DROP
-ed from the michelson stack) so if the returned ticket isn't stored in some form by your contract, it will be fully consumed.
To read the content of a ticket, you need to use pattern matching
function split_ticket : ticket ('value) -> nat * nat -> option (ticket('value) * ticket ('value))
To partially use/consume a ticket, you have to split it. Provided a ticket and two amounts, two new tickets will be returned to you if the two amounts match the amount of the original ticket.
#
LinearityIf a contract storage type contains a ticket, you must destructure the parameter-storage pair within the body to preserve storage linearity (e.g. avoid DUP
-ing storage).
For the same reasons, if tickets are stored in a map
/big_map
you must use the new operator get_and_update
to update your bindings.