Skip to content
On this page

Tickets โ€‹

Tickets of content type t have type sp.TTicket(t).
The corresponding type in Michelson is

Michelson ticket

See reference Tickets template

Create a ticket โ€‹

sp.ticket(content, amount)
Create a ticket with content and amount. If content is of type t, the return type is sp.TTicket(t). The amount has to be of type sp.TNat.

Example โ€‹

python
ticket = sp.ticket("Can be a string", sp.nat(1))
Michelson TICKET

High Level Functions โ€‹

Read ticket โ€‹

sp.read_ticket(ticket)
Read the data of a ticket and return a Python object with four fields ticketer, content, amount, and copy.

Example โ€‹

python
read_ticket = sp.read_ticket(ticket)

The output read_ticket object is not a SmartPy expression and cannot be passed as an expression to regular SmartPy functions. However, it can be passed to regular Python functions thanks to meta-programming.

WARNING

It is an error to access ticket again after this command, and read_ticket.copy must be used instead.

If ticket is of type sp.TTicket(t), then read_ticket.ticketer is of type sp.TAddress, read_ticket.content of type t, and read_ticket.amount of type sp.TNat.

Michelson READ_TICKET

Split ticket โ€‹

sp.split_ticket(ticket, q1, q2)
Split ticket into two tickets of amounts q1 and q2. These two amounts must sum up to ticket's value, otherwise sp.none is returned.

Example โ€‹

python
sp.split_ticket(ticket, q1, q2)

If ticket is of type sp.TTicket(t), this returns a value of type sp.TOption(sp.TPair(sp.TTicket(t), sp.TTicket(t))).

Michelson SPLIT_TICKET

Join tickets โ€‹

sp.join_tickets(ticket1, ticket2)
Return a new ticket with the sum of the amounts in ticket1 and ticket2. The two tickets must have the same contents, or an error is raised.

Example โ€‹

python
sp.join_tickets(ticket1, ticket2)

Both tickets must have the same type sp.TTicket(t), which is also the return type.

Michelson JOIN_TICKETS

Low Level Functions โ€‹

Read ticket โ€‹

sp.read_ticket_raw(ticket)
Like sp.read_ticket(ticket) when the output is two elements.

Example โ€‹

python
sp.read_ticket_raw(ticket)
Michelson READ_TICKET

Split ticket โ€‹

sp.split_ticket_raw(ticket, q1, q2)
Like sp.split_ticket(ticket, q1, q2) when the output is two elements.

Example โ€‹

python
sp.split_ticket_raw(ticket, q1, q2)
Michelson SPLIT_TICKET

Join tickets โ€‹

sp.join_tickets_raw(tickets)
Like sp.join_tickets(ticket1, ticket2) where tickets is a pair of tickets.

Example โ€‹

python
sp.join_tickets_raw(tickets)
Michelson JOIN_TICKETS

Testing Tickets โ€‹

sp.test_ticket(ticketer, content, amount)
Create a new ticket issued by the locally defined contract ticketer. This is meant to be used for testing purposes in scenarios.

Example โ€‹

python
ticket = sp.test_ticket(ticketer, content, amount)