A decentralized marketplace for minting, buying, selling, and transferring concert tickets on the Stacks blockchain using Clarity smart contracts.
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.
- 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
- 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)
- 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
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
}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 your ticket on the marketplace.
(list-for-resale (ticket-id uint) (resale-price uint))Returns: (ok true)
Purchase a listed ticket. Automatically transfers payment minus platform fee to seller.
(buy-ticket (ticket-id uint))Returns: (ok true)
Remove your ticket from the marketplace.
(cancel-listing (ticket-id uint))Returns: (ok true)
Mark your ticket as used (event check-in).
(use-ticket (ticket-id uint))Returns: (ok true)
Gift or transfer your ticket to another user.
(transfer-ticket (ticket-id uint) (recipient principal))Returns: (ok true)
Retrieve ticket information.
(get-ticket (ticket-id uint))Returns: (optional ticket-data)
Get all ticket IDs owned by a user.
(get-user-tickets (user principal))Returns: (list uint)
Get all ticket IDs for a specific event.
(get-event-tickets (event-name (string-ascii 100)))Returns: (list uint)
Calculate platform fee for a given price.
(calculate-resale-fee (price uint))Returns: uint
Update the platform fee percentage (max 20%).
(set-platform-fee (new-fee uint))Requires: Contract owner only
Pause/unpause the contract for emergency situations.
(toggle-pause)Requires: Contract owner only
Pre-approve event names for additional security.
(validate-event (event-name (string-ascii 100)))Requires: Contract owner only
Withdraw accumulated platform fees.
(emergency-withdraw (amount uint))Requires: Contract owner only
| 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 |
;; 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)When a ticket is purchased on the resale market:
- Buyer sends full resale price in STX
- Platform fee (5%) is transferred to contract owner
- Remaining amount (95%) is transferred to seller
- Ticket ownership is transferred to buyer
- Ticket is removed from marketplace
Example: For a 100 STX ticket:
- Seller receives: 95 STX
- Platform receives: 5 STX
β 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