Quick Start: For complete setup, deployment, and interface operations see RUN.md
BlockTix/
│
├── contracts/ # Smart contract development (Foundry)
│ ├── src/
│ │ ├── BlockTixMain.sol # Primary ticketing contract (399 lines)
│ │ ├── TicketNFT.sol # ERC-721 implementation (186 lines)
│ │ ├── PriceOracle.sol # Dynamic pricing engine (289 lines)
│ │ └── interfaces/
│ │ ├── IBlockTix.sol # Main contract interface
│ │ ├── ITicketNFT.sol # NFT interface specifications
│ │ └── IPriceOracle.sol # Price oracle interface
│ │
│ ├── test/
│ │ └── unit/
│ │ ├── BlockTixMain.t.sol # Unit tests (31 tests)
│ │ ├── TicketNFT.t.sol # NFT tests (32 tests)
│ │ └── PriceOracle.t.sol # Pricing tests (40 tests)
│ │
│ ├── script/
│ │ └── Deploy.s.sol # Deployment script
│ │
│ ├── lib/ # Dependencies (managed by Foundry)
│ │ ├── forge-std/ # Foundry standard library
│ │ └── openzeppelin-contracts/# OpenZeppelin v5.x
│ │
│ ├── foundry.toml # Foundry configuration
│ ├── .env.example # Environment template
│ └── remappings.txt # Import remappings
│
├── metrics/ # Sprint 4 metrics & analysis
│ ├── METRICS-SUMMARY.md # Quick metrics overview
│ ├── coverage/ # Test coverage reports (97%+)
│ ├── gas/ # Gas optimization analysis (24-44% savings)
│ ├── latency/ # Transaction performance data
│ ├── security/ # Slither security analysis
│ └── usability/ # Usability improvements documentation
│
├── scripts/ # Helper scripts
│ ├── test-all.sh # Run all tests
│ ├── measure-gas.sh # Generate gas snapshot
│ ├── generate-metrics.sh # Generate all metrics
│ └── deploy-sepolia.sh # Deploy to Sepolia
│
├── archive/ # Progress tracking files
│ ├── COMPLETED.md # Phase completion tracking
│ ├── PROGRESS.md # Detailed progress log
│ └── ROADMAP.md # Implementation roadmap
│
├── architecture/ # System architecture diagrams
├── logs/ # Deployment and test logs
│
├── README.md # This file
├── RUN.md # Operations runbook
├── AIUSAGE.txt # AI usage documentation
├── ARCHITECTURE.md # Architecture documentation
├── CONTRACT.md # Contract API documentation
├── MODEL.md # Threat model & permissions
├── DEMO.md # Live demo walkthrough
├── .gitignore
└── LICENSE
- Git
- Foundry toolkit (forge, cast, anvil)
- Sepolia testnet ETH (for testnet deployment)
# Navigate to contracts directory
cd contracts/
# Install dependencies
forge install
# Copy environment variables
cp .env.example .env
# Edit .env with your keys (NEVER commit actual keys)
# Compile contracts
forge build
# Run all tests (105 tests)
forge test -vv
# Run tests with gas reporting
forge test --gas-report
# Generate coverage report
forge coverage
# Generate gas snapshot
forge snapshotLocation: contracts/test/unit/
Test Coverage:
- BlockTixMain.t.sol : 31 tests covering event creation, ticket purchasing, transfers, withdrawals, fee management
- TicketNFT.t.sol : 32 tests covering minting, burning, URI management, ERC-721 compliance
- PriceOracle.t.sol : 40 tests covering pricing calculations, surge pricing, time decay, access control
Commands:
forge test: Run all testsforge test -vv: Run with verbose loggingforge test --match-test testSpecificFunction: Run specific testforge test --match-contract BlockTixMain: Run tests for specific contractforge coverage: Generate coverage report./scripts/test-all.sh: Run all tests (helper script)./scripts/generate-metrics.sh: Generate all metrics files
Test Results:
- Total Tests : 105
- Pass Rate : 100% (105/105 passing)
- Coverage : 97%+ (exceeds 95% target)
- Compilation : SUCCESS (0 errors, 0 warnings)
Commands:
forge snapshot: Generate gas snapshotforge snapshot --diff: Compare with previous snapshotforge test --gas-report: Display gas usage during tests./scripts/measure-gas.sh: Generate gas snapshot (helper script)
Script Location: contracts/script/Deploy.s.sol
Steps:
- Start Anvil local testnet:
anvil- Deploy contracts (in separate terminal):
cd contracts/
forge script script/Deploy.s.sol:Deploy --rpc-url http://localhost:8545 --broadcastDeployment Configuration:
- Platform Fee : 250 basis points (2.5%)
- Demand Multiplier : 1000 basis points (10%)
- Time Decay : 500 basis points (5%)
- Base URI : https://blocktix.io/metadata/
Deployment Order:
- PriceOracle contract
- TicketNFT contract
- BlockTixMain contract
- Configure cross-contract references
- Verify deployment
Local Deployment Addresses (Anvil Chain ID 31337):
- BlockTixMain : 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
- TicketNFT : 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
- PriceOracle : 0x5FbDB2315678afecb367f032d93F642f64180aa3
Command:
forge script script/Deploy.s.sol:Deploy --rpc-url $SEPOLIA_RPC_URL --broadcast --verifySepolia Deployment Addresses(Chain ID 11155111):
- BlockTixMain: 0x4572b63734CE8395CB32E199cfb2239f9e7D7095
- TicketNFT: 0xF82bA5dac740Ab9955800ff5e807d16bC4014861
- PriceOracle: 0x3c7D84D7AF3Fb18AcFFF66d310fca456eB76245e
- Deployer Address: https://sepolia.etherscan.io/address/0x1ba94e09c8b1d8f54a43a6eb269c4da10cc111cb
Etherscan Links:
Command:
forge verify-contract --chain sepolia <CONTRACT_ADDRESS> src/BlockTixMain.sol:BlockTixMain --etherscan-api-key $ETHERSCAN_API_KEYSee Also: DEMO.md for complete live demo walkthrough
BlockTix implements a modular three-contract architecture for decentralized event ticketing with the following key features:
- Event creation and management by organizers
- Dynamic pricing with surge pricing thresholds
- ERC-721 NFT tickets with resale controls
- Platform fee distribution
- Pull payment pattern for withdrawals
Purpose: Central hub contract managing events, ticket sales, and financial flows
Key Features:
- Event creation with customizable parameters (total tickets, base price, event date, resale markup limits)
- Ticket purchasing with dynamic pricing via PriceOracle integration
- Ticket transfer/resale with enforced markup limits
- Ticket usage tracking (check-in functionality)
- Event cancellation by organizers
- Withdrawal system with platform fee distribution (2.5% default)
- Access control (Ownable for admin functions)
- Reentrancy protection on all payable functions
Core Functions:
createEvent(): Create new ticketed eventspurchaseTicket(): Buy tickets with dynamic pricingtransferTicket(): Resell tickets with price validationuseTicket(): Mark tickets as used (organizer only)cancelEvent(): Cancel events (organizer only)withdraw(): Withdraw accumulated fundsupdatePlatformFee(): Update platform fee (owner only)
Helper Functions (Sprint 4):
getAvailableTickets(): Check remaining tickets for eventgetMaxResalePrice(): Calculate maximum allowed resale pricegetTicketPrice(): Preview current ticket priceisEventSelling(): Check if event is accepting purchasesgetEventStats(): Get sales statistics (sold/total/percentage)
State Management:
- Event struct : eventId, organizer, name, totalTickets, ticketsSold, basePrice, eventDate, isActive, maxResaleMarkup
- Ticket struct : ticketId, eventId, currentOwner, purchasePrice, isUsed
- Mappings for events, tickets, pending withdrawals
Purpose: ERC-721 NFT contract representing event tickets
Key Features:
- Full ERC-721 compliance (extends OpenZeppelin ERC721URIStorage)
- Safe minting with metadata URI storage
- Batch minting capability for efficiency
- Burn functionality for expired/used tickets
- Base URI management system
- Access control (only BlockTixMain can mint)
- Token existence tracking
- Event-to-token mapping
Core Functions:
mint(): Mint single ticket NFTbatchMint(): Mint multiple tickets efficientlyburn(): Burn ticket NFTssetTokenURI(): Set individual token metadatasetBaseURI(): Update base URI for all tokensgetEventId(): Get event ID for a ticket
Purpose: Dynamic pricing engine with surge pricing and time decay
Key Features:
- Dynamic pricing algorithm based on demand
- Surge pricing with 3 thresholds:
- 50% sold : 5% price increase
- 75% sold : 10% price increase
- 90% sold : 20% price increase
- Time-based pricing adjustments (early bird discounts)
- Price validation for resales
- Platform fee calculation logic
- Price history tracking per event
- Emergency pause functionality
- Configurable surge multipliers
Core Functions:
calculatePrice(): Calculate dynamic price based on demandcalculatePriceWithTimeDecay(): Calculate price with time adjustmentsvalidateResalePrice(): Validate resale prices against markup limitssetDemandMultiplier(): Update demand multipliersetTimeDecay(): Update time decay factorsetSurgeMultipliers(): Configure surge pricing thresholdsgetPriceHistory(): Retrieve price history for events
-
Event Creation Flow:
- Organizer calls
BlockTixMain.createEvent() - Event struct created and stored
- EventCreated event emitted
- Organizer calls
-
Ticket Purchase Flow:
- Buyer calls
BlockTixMain.purchaseTicket(eventId)with ETH payment - BlockTixMain queries PriceOracle for current price
- BlockTixMain calls TicketNFT.mint() to create NFT
- Ticket struct created and ownership assigned
- Platform fee calculated and added to pendingWithdrawals
- Organizer share added to pendingWithdrawals
- Excess payment refunded to buyer
- TicketPurchased event emitted
- Buyer calls
-
Ticket Resale Flow:
- Seller approves BlockTixMain to transfer NFT
- Seller calls
BlockTixMain.transferTicket(ticketId, buyer)with ETH payment - BlockTixMain validates resale price against markup limit
- Platform fee calculated from resale price
- Seller earnings added to pendingWithdrawals
- NFT transferred via TicketNFT contract
- Ticket ownership updated
- TicketTransferred event emitted
-
Withdrawal Flow:
- User calls
BlockTixMain.withdraw() - Contract sends accumulated balance to user
- WithdrawalProcessed event emitted
- User calls
- ReentrancyGuard: Protects all state-changing payable functions
- Ownable: Restricts admin functions to contract owner
- Pausable: Emergency pause on PriceOracle
- Custom Errors: Gas-efficient error handling
- Checks-Effects-Interactions: External calls after state updates
- Pull Payment Pattern: Users withdraw rather than automatic transfers
- Access Modifiers:
onlyBlockTixMainon TicketNFT and PriceOracle functions
- OpenZeppelin Contracts v5.x:
- ERC721.sol, ERC721URIStorage.sol
- Ownable.sol
- ReentrancyGuard.sol
- Pausable.sol
- Foundry forge-std for testing
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
SEPOLIA_RPC_URL=https://sepolia.infura.io/v3/YOUR_INFURA_KEY
ETHERSCAN_API_KEY=YOUR_ETHERSCAN_API_KEYNote: The private key above is the default Anvil test key. NEVER use this on mainnet or with real funds.
Metrics Location: metrics/ folder (see METRICS-SUMMARY.md for overview)
Security:
- ✓ Slither static analysis completed
- ✓ 3 reentrancy vulnerabilities fixed (1 Medium, 2 Low)
- ✓ 0 High/Medium/Low severity issues remaining
- ✓ Security report:
metrics/security/slither-summary.txt
Gas Optimization:
- ✓ 24-44% gas reduction achieved (target: 20%)
- ✓ Struct packing optimization (8 slots → 3 slots)
- ✓ Immutable variables for contract references
- ✓ Details:
metrics/gas/gas-improvements.txt
Usability Improvements:
- ✓ 12 enhancements (4 validations, 3 error improvements, 5 helpers)
- ✓ Helper functions: getAvailableTickets(), getMaxResalePrice(), etc.
- ✓ Better error messages with parameters
- ✓ Details:
metrics/usability/usability-improvements.txt
Performance:
- ✓ 9 Sepolia transactions tested (100% success rate)
- ✓ Average latency: 24-35 seconds
- ✓ Details:
metrics/latency/latency.csv
Feature Completeness:
- ✓ 100% of planned features implemented
- ✓ All roadmap phases complete
- ✓ Details:
metrics/coverage/feature-completeness.txt
RUN.md: Complete operations runbook (setup, CLI commands, Etherscan)AIUSAGE.txt: AI usage documentation for all sprintsARCHITECTURE.md: System architecture with diagramsCONTRACT.md: Complete contract API documentationMODEL.md: Threat model and permission matrixDEMO.md: Live demo walkthrough with cast commandsmetrics/METRICS-SUMMARY.md: Sprint 4 metrics overviewarchive/: Progress tracking files (COMPLETED.md, PROGRESS.md, ROADMAP.md)
All Phases Complete:
- ✓ Phase 1: Environment Setup
- ✓ Phase 2: Smart Contract Implementation
- ✓ Phase 3: Testing Suite (105 tests, 97%+ coverage)
- ✓ Phase 4: Gas Optimization (24-44% reduction)
- ✓ Phase 5: Deployment (Sepolia verified)
- ✓ Phase 6: Operations Runbook
- ✓ Phase 7: Performance Measurement
- ✓ Phase 8: Security Analysis
- ✓ Sprint 4: Feature Completeness & Polish
Final Statistics:
- Total Contracts : 3 (874 lines)
- Total Interfaces : 3
- Total Test Files : 3 (1,850 lines)
- Total Tests : 105
- Test Pass Rate : 100%
- Test Coverage : 97%+ (all core contracts)
- Gas Optimization : 24-44% savings
- Security Issues : 0 critical remaining
- Compilation Status : SUCCESS
- Sepolia Deployment : LIVE & VERIFIED
Group 4 : BlockTix Team
Repository maintained according to 67-404 Fall 2025 course requirements.
This project is developed for educational purposes as part of CMU 67-404.