Version: 25.0.0
Tickets
Using tickets with octez.js
What is a ticket?
Tickets are a new feature introduced to the Tezos blockchain with the Edo upgrade. Tickets are fungible tokens represented by 3 values:
- The address of the contract that created the ticket
- A value of a comparable type
- An amount of type
nat
Tickets open a wide range of permission use cases where they can be used to allow access to certain functionalities of a smart contract to one or multiple users. The goal of tickets explains 2 of their main characteristics: they can only be created on-chain and they cannot be duplicated.
In this regard, the only interaction available to octez.js with tickets is reading them. This can be particularly useful to inform users if they have access to the functionality of a contract before they send a transaction to a forbidden entrypoint.
How to read a ticket with octez.js?
Although tickets can be stored in any part of the storage of a contract, it is more common to see them in complex types like a pair or a map/big map. octez.js treats tickets like any other value fetched from a contract and they are available in JavaScript/TypeScript as an object with 3 properties:
{ ticketer: string; value: any; amount: BigNumber }
-
The
ticketerproperty is a string representing the address of the contract that issued the ticket. As tickets can only be joined if they have the same ticketer and value, this is the guarantee that the ticket hasn’t been tampered with. -
The
valueproperty holds a value of a comparable type. It is of typeanyin octez.js as the value can be of different TypeScript types according to its Michelson type. -
The
amountproperty is a non-negativeBigNumberin octez.js and it’s the only property of a ticket likely to change after the ticket creation.
Examples of values returned when reading a ticket with octez.js
| Ticket in Michelson | Ticket with octez.js | |
|---|---|---|
| Value type: int | (pair address (pair int nat)) (Pair “KT1ABC…” (Pair 123 5)) | { ticketer: "KT1ABC...", value: BigNumber(123), amount: BigNumber(5) } |
| Value type: string | (pair address (pair string nat)) (Pair “KT1ABC…” (Pair “octez.js” 5)) | { ticketer: "KT1ABC...", value: "octez.js", amount: BigNumber(5) } |
| Value type: bool | (pair address (pair bool nat)) (Pair “KT1ABC…” (Pair True 5)) | { ticketer: "KT1ABC...", value: true, amount: BigNumber(5) } |
| Value type: bytes | (pair address (pair bytes nat)) (Pair “KT1ABC…” (Pair “0xCAFE” 5)) | { ticketer: "KT1ABC...", value: "CAFE", amount: BigNumber(5) } |
| Value type: option | (pair address (pair (option string) nat)) (Pair “KT1ABC…” (Pair (Some “Tezos”) 5)) | { ticketer: "KT1ABC...", value: "Tezos", amount: BigNumber(5) } |
| Value type: option | (pair address (pair (option string) nat)) (Pair “KT1ABC…” (Pair None 5)) | { ticketer: "KT1ABC...", value: null, amount: BigNumber(5) } |
| Value type: pair int string | (pair address (pair (pair int string) nat)) (Pair “KT1ABC…” (Pair (Pair 7 “Tacos”) 5)) | { ticketer: "KT1ABC...", value: { 0: BigNumber(7), 1: "Tacos" }, amount: BigNumber(5) } |