Skip to content
On this page

Tickets

Tezos has so-called tickets, which are authenticated quantities issued by contracts. A ticket of type sp.ticket[t] has three elements:

  • A source, indicating the contract that issued the ticket.

  • A value of type t.

  • A quantity of type sp.nat.

sp.ticket(content: t, quantity: sp.nat) → sp.ticket[t]

Create a ticket with the given content and quantity. The ticket source is the address of sp.self_address.

sp.read_ticket(ticket: sp.ticket[t]) → sp.pair[sp.tuple[sp.address, t, sp.nat], sp.ticket[t]]

Reads the contents of a ticket. Returns a pair of:

  • The ticket data, itself a triple of the ticket's source, value, and quantity.

  • A copy of the original ticket that can still be used.

Note that mentioning a ticket consumes it, i.e. the argument to sp.read_ticket cannot be used again. Instead the returned copy can still be used.

sp.join_tickets(sp.pair[sp.ticket[t], sp.ticket[t]]) → sp.option[sp.ticket[t]]

Makes two tickets into one by adding up their quantities. Returns None if the tickets differ in their source or value.

sp.split_ticket(ticket: sp.ticket[t], amounts: sp.pair[sp.nat, sp.nat]) → sp.option[sp.pair[sp.ticket[t], sp.ticket[t]]]

Splits a ticket into two parts. sp.split_ticket(ticket, (amount1, amount2)) returns two tickets with the specified amounts. None is returned if amount1 + amount2 is not equal to ticket's amount.