Skip to main content

Independent Ticketing System Package

In this tutorial, we will build an Independent Ticketing System utilizing the Move language for blockchain contracts and the IOTA dApp kit for the frontend application. The project begins with creating a Move package, building and deploying it on the testnet network. Once the backend contract is operational, we will develop the frontend dApp.

Sequence Diagram

This sequence diagram illustrates the flow of interactions within a decentralised ticketing system involving the Owner, User, Blockchain, and the IndependentTicketingSystem contract. The process begins with the Owner deploying the contract to the Blockchain, which initializes the contract. The Owner then mints a TicketNFT, specifying event details, while the contract verifies conditions like ownership and seat availability before transferring the NFT. Next, the Owner can whitelist a User to enable ticket purchases and then activate the ticket for sale. When a User buys a ticket, the contract validates seat availability and the whitelist status, processes payment, and transfers the NFT to the buyer. For resale, the User can list the NFT at a new price, and the contract handles royalty payments, ensures the buyer is whitelisted, and updates the Blockchain accordingly. The diagram also covers NFT burning, adding users to the whitelist, and creating new ticket objects for testing purposes. Each step ensures the system maintains security, ownership, and payment flow on the Blockchain.

Prerequisites

Create a Move Package

Run the following command to create a Move package:

iota move new independent_ticketing_system && cd independent_ticketing_system

Package Overview

Struct and Constants

  • TicketNFT - This struct contains the details of an NFT, including the event ID, event date, royalty percentage, creator, total seats, price, and owner.
  • CreatorCap - This struct acts a creator cap for the package.
  • EventObject - This struct contains the total number of seats for an event and an array of available tickets to buy.
  • InitiateResale - This struct defines an shared object which will be created when a user wants to resale the NFT.

init

In Move, the init function only runs once at package publication. The init function will create three shared_object type objects:

  • CreatorCap will use to verify the creator of the package.
  • EventObject - it will contain the total number of seat for the event which will update as per minting the tickets and an array of all the NFT which are minted by the creator and are available to buy. To buy tickets, the first user needs to be whitelisted.
independent_ticketing_system/sources/independent_ticketing_system.move
loading...

mint_ticket

  • This function allows the creator to mint NFTs to their address.
  • The creator must provide the event object id so that things like the total number of seats can be checked. Also the creator has to own a creator capability to proof they are in fact the creator
  • Only the creator is authorized to mint these NFTs; no one else can perform this action.
independent_ticketing_system/sources/independent_ticketing_system.move
loading...

enable_ticket_to_buy

  • This function can only be called by the creator, as it enables the minted NFTs to be available for purchase.
  • It updates the EventObject shared object by adding the NFT to its available_tickets_to_buy field array.
independent_ticketing_system/sources/independent_ticketing_system.move
loading...

transfer_ticket

  • This function transfers the ownership of the nft to the recipient address.
  • The creator will not receive any royalty fee when this function is called.
independent_ticketing_system/sources/independent_ticketing_system.move
loading...

resale

  • This function makes the nft available for resale.
  • The recipient address must first be whitelisted for the nft. To whitelist the recipient, the user will call the whitelist_buyer function.
  • The function creates a new object called InitiateResale and transfers its ownership to the recipient address.
independent_ticketing_system/sources/independent_ticketing_system.move
loading...

buy_ticket

  • This function allows the purchase of NFTs listed in the EventObject object.
  • The buyer must first be whitelisted.
  • The object ID of the EventObject object must be provided when calling the function.
independent_ticketing_system/sources/independent_ticketing_system.move
loading...

buy_resale

  • This function transfers the ownership of the NFT wrapped in the InitiateResale object.
  • The caller's address must match the buyer address of the InitiateResale object.
  • A royalty fee will be transferred to the creator of the NFT by the caller of this function.
independent_ticketing_system/sources/independent_ticketing_system.move
loading...

burn

  • This function burns the NFT, removing the NFT object from the owner's account.
  • Only the NFT's owner is authorized to burn the NFT.
independent_ticketing_system/sources/independent_ticketing_system.move
loading...

whitelist_buyer

  • This function allows the owner of an NFT to whitelist a user.
  • Once whitelisted, the user becomes eligible to purchase the NFT.
independent_ticketing_system/sources/independent_ticketing_system.move
loading...

See the full example of the contract on github .

Write Unit Tests

After creating the module write the test for all the functions. Move the below code to the independent_ticketing_system_test.move file:

independent_ticketing_system/tests/independent_ticketing_system_test.move
loading...

Publish the Package

Publish the package to the IOTA Testnet using the following command:

iota client publish