Skip to content

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 

Repository files navigation

Concert Ticket Resale Smart Contract

A decentralized marketplace for minting, buying, selling, and transferring concert tickets on the Stacks blockchain using Clarity smart contracts.

Overview

This smart contract provides a complete ticketing solution that prevents fraud, enables secure resales, and automates platform fee collection. Tickets are stored on-chain with full provenance tracking from minting to usage.

Key Features

🎫 Ticket Management

  • Mint Tickets: Create tickets with event details, pricing, dates, and seat information
  • Use Tickets: Mark tickets as used to prevent double-spending
  • Transfer Tickets: Gift or send tickets to other users
  • Track History: Full ownership and transaction history

πŸ’° Marketplace

  • List for Resale: Set custom resale prices for your tickets
  • Buy Tickets: Purchase listed tickets with automatic payment splitting
  • Cancel Listings: Remove tickets from marketplace anytime
  • Platform Fees: Automated 5% fee collection (configurable by admin)

πŸ”’ Security Features

  • Expiration validation (can't sell/use expired tickets)
  • Usage prevention (can't resell used tickets)
  • Ownership verification on all operations
  • Self-transfer prevention
  • Emergency pause mechanism
  • Input validation on all user data

Data Structure

Each ticket contains:

{
    event-name: string (max 100 chars)
    original-owner: principal
    current-owner: principal
    original-price: uint
    resale-price: uint
    for-sale: bool
    event-date: uint (block height)
    seat-section: string (max 50 chars)
    used: bool
}

Core Functions

User Functions

mint-ticket

Create a new ticket.

(mint-ticket 
    (event-name (string-ascii 100))
    (price uint)
    (event-date uint)
    (seat-section (string-ascii 50)))

Returns: (ok ticket-id)

list-for-resale

List your ticket on the marketplace.

(list-for-resale (ticket-id uint) (resale-price uint))

Returns: (ok true)

buy-ticket

Purchase a listed ticket. Automatically transfers payment minus platform fee to seller.

(buy-ticket (ticket-id uint))

Returns: (ok true)

cancel-listing

Remove your ticket from the marketplace.

(cancel-listing (ticket-id uint))

Returns: (ok true)

use-ticket

Mark your ticket as used (event check-in).

(use-ticket (ticket-id uint))

Returns: (ok true)

transfer-ticket

Gift or transfer your ticket to another user.

(transfer-ticket (ticket-id uint) (recipient principal))

Returns: (ok true)

Read-Only Functions

get-ticket

Retrieve ticket information.

(get-ticket (ticket-id uint))

Returns: (optional ticket-data)

get-user-tickets

Get all ticket IDs owned by a user.

(get-user-tickets (user principal))

Returns: (list uint)

get-event-tickets

Get all ticket IDs for a specific event.

(get-event-tickets (event-name (string-ascii 100)))

Returns: (list uint)

calculate-resale-fee

Calculate platform fee for a given price.

(calculate-resale-fee (price uint))

Returns: uint

Admin Functions

set-platform-fee

Update the platform fee percentage (max 20%).

(set-platform-fee (new-fee uint))

Requires: Contract owner only

toggle-pause

Pause/unpause the contract for emergency situations.

(toggle-pause)

Requires: Contract owner only

validate-event

Pre-approve event names for additional security.

(validate-event (event-name (string-ascii 100)))

Requires: Contract owner only

emergency-withdraw

Withdraw accumulated platform fees.

(emergency-withdraw (amount uint))

Requires: Contract owner only

Error Codes

Code Constant Description
u100 err-owner-only Action requires contract owner
u101 err-not-found Ticket doesn't exist
u102 err-unauthorized Not the ticket owner
u103 err-already-sold Ticket already sold
u104 err-not-for-sale Ticket not listed for sale
u105 err-insufficient-payment Payment amount too low
u106 err-expired Event date has passed
u107 err-invalid-price Price is zero or invalid
u108 err-already-used Ticket already used
u109 err-transfer-failed STX transfer failed
u110 err-invalid-input Invalid input data
u111 err-self-transfer Cannot transfer to self

Usage Example

;; 1. Mint a ticket
(contract-call? .ticket-resale mint-ticket 
    "Coldplay World Tour 2025" 
    u1000000 
    u15000 
    "Section A, Row 5")

;; 2. List ticket for resale
(contract-call? .ticket-resale list-for-resale u1 u1200000)

;; 3. Buy a listed ticket
(contract-call? .ticket-resale buy-ticket u1)

;; 4. Use ticket at event
(contract-call? .ticket-resale use-ticket u1)

;; 5. Check ticket details
(contract-call? .ticket-resale get-ticket u1)

Payment Flow

When a ticket is purchased on the resale market:

  1. Buyer sends full resale price in STX
  2. Platform fee (5%) is transferred to contract owner
  3. Remaining amount (95%) is transferred to seller
  4. Ticket ownership is transferred to buyer
  5. Ticket is removed from marketplace

Example: For a 100 STX ticket:

  • Seller receives: 95 STX
  • Platform receives: 5 STX

Security Considerations

βœ… Tested Validations:

  • All string inputs are validated for non-empty content
  • Event dates must be in the future
  • Prices must be greater than zero
  • Ticket ownership verified on all operations
  • Used tickets cannot be resold or transferred
  • Expired tickets cannot be sold or used

βœ… Best Practices:

  • Use tickets before event expiration
  • Cancel listings before transferring tickets
  • Verify ticket details before purchasing
  • Check event dates match your expectations

About

The Concert Ticket Resale smart contract is a blockchain-based ticketing platform built on Clarity for the Stacks blockchain. It provides a complete solution for creating, trading, and managing event tickets with built-in fraud prevention, transparent pricing, and automated fee distribution.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors