Skip to content

Repository files navigation

🎫 NFT Ticketing System

A decentralized ticketing platform built on blockchain technology that allows users to mint, purchase, transfer, and verify event tickets as NFTs (Non-Fungible Tokens). This project combines Web3 technology with a modern full-stack application to prevent ticket fraud and enable secure peer-to-peer ticket transfers.

🌟 Features

  • πŸ”— Blockchain-Based Tickets: Each ticket is a unique ERC-721 NFT on the blockchain
  • 🦊 MetaMask Integration: Connect your crypto wallet to interact with the platform
  • 🎟️ Event Management: Browse and purchase tickets for various events
  • πŸ“± QR Code Verification: Generate and verify tickets using QR codes
  • πŸ’Έ Secure Transfers: Transfer tickets directly between wallets
  • πŸ” Ticket Validation: Verify ticket authenticity on the blockchain
  • πŸ“Š Transaction History: Track all ticket purchases and transfers
  • 🎨 Modern UI: Built with React, TypeScript, and Tailwind CSS

πŸ—οΈ Architecture

The project consists of three main components:

1. Frontend (React + TypeScript + Vite)

  • Modern React application with TypeScript
  • MetaMask wallet integration
  • Responsive UI with Tailwind CSS
  • React Router for navigation
  • QR code generation and scanning

2. Backend (Node.js + Express + MongoDB)

  • RESTful API for event and transaction management
  • MongoDB database for storing event details
  • Integration with blockchain for ticket verification
  • CORS-enabled API endpoints

3. Smart Contracts (Solidity + Hardhat)

  • ERC-721 NFT standard implementation
  • Custom ticket minting and management logic
  • Event-based ticket tracking
  • OpenZeppelin contracts for security

πŸ› οΈ Tech Stack

Frontend

  • React 18 - UI library
  • TypeScript - Type-safe JavaScript
  • Vite - Build tool and dev server
  • Ethers.js - Ethereum library for Web3 interaction
  • Tailwind CSS - Utility-first CSS framework
  • React Router - Client-side routing
  • Lucide React - Icon library
  • QRCode.js - QR code generation

Backend

  • Node.js - JavaScript runtime
  • Express - Web framework
  • MongoDB - NoSQL database
  • Mongoose - MongoDB ODM
  • Ethers.js - Blockchain interaction
  • CORS - Cross-origin resource sharing
  • dotenv - Environment variable management

Smart Contracts

  • Solidity ^0.8.20 - Smart contract language
  • Hardhat - Ethereum development environment
  • OpenZeppelin - Secure smart contract library
  • ERC-721 - NFT token standard

πŸ“‹ Prerequisites

Before running this project, make sure you have:

  • Node.js (v16 or higher)
  • npm or yarn
  • MongoDB (local or cloud instance)
  • MetaMask browser extension
  • Git

πŸš€ Installation & Setup

1. Clone the Repository

git clone https://github.com/Jiyasingh06/Digital_Payment_Project.git
cd Digital_Payment_Project-main

2. Install Dependencies

Frontend

npm install

Backend

cd backend
npm install
cd ..

Smart Contracts

cd smart-contract
npm install
cd ..

3. Environment Configuration

Create a .env file in the root directory:

# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/ticketnft

# Backend Port
PORT=5000

# Blockchain Configuration
RPC_URL=http://127.0.0.1:8545
PRIVATE_KEY=your_private_key_here

# Contract Address (will be set after deployment)
CONTRACT_ADDRESS=your_deployed_contract_address

4. Start MongoDB

Make sure MongoDB is running on your system:

# For local MongoDB
mongod

Or use a cloud MongoDB service like MongoDB Atlas.

5. Deploy Smart Contracts

Start Local Blockchain (Hardhat)

cd smart-contract
npm run node

Deploy Contract (in a new terminal)

cd smart-contract
npm run deploy:local

Copy the deployed contract address and update it in:

  • .env file
  • src/web3/deployment.json

6. Seed Database (Optional)

cd backend
node seedDatabase.js

7. Start the Application

Terminal 1: Start Backend Server

cd backend
npm start
# or for development with auto-reload
npm run dev

Terminal 2: Start Frontend

npm run dev

The application will be available at:

πŸ“ Project Structure

Digital_Payment_Project-main/
β”œβ”€β”€ src/                      # Frontend source code
β”‚   β”œβ”€β”€ components/           # React components
β”‚   β”‚   β”œβ”€β”€ Header.tsx
β”‚   β”‚   └── MetaMaskPrompt.tsx
β”‚   β”œβ”€β”€ context/              # React context providers
β”‚   β”‚   └── WalletContext.tsx
β”‚   β”œβ”€β”€ pages/                # Page components
β”‚   β”‚   β”œβ”€β”€ EventsPage.tsx
β”‚   β”‚   β”œβ”€β”€ MyTicketsPage.tsx
β”‚   β”‚   β”œβ”€β”€ TransferPage.tsx
β”‚   β”‚   └── VerifyPage.tsx
β”‚   β”œβ”€β”€ utils/                # Utility functions
β”‚   β”‚   β”œβ”€β”€ api.js
β”‚   β”‚   └── qrcode.js
β”‚   β”œβ”€β”€ web3/                 # Web3 integration
β”‚   β”‚   β”œβ”€β”€ connectWallet.js
β”‚   β”‚   β”œβ”€β”€ contract.js
β”‚   β”‚   β”œβ”€β”€ contractABI.json
β”‚   β”‚   └── deployment.json
β”‚   β”œβ”€β”€ App.tsx               # Main app component
β”‚   └── main.tsx              # Entry point
β”‚
β”œβ”€β”€ backend/                  # Backend API
β”‚   β”œβ”€β”€ models/               # MongoDB models
β”‚   β”‚   β”œβ”€β”€ Event.js
β”‚   β”‚   └── Transaction.js
β”‚   β”œβ”€β”€ routes/               # API routes
β”‚   β”‚   β”œβ”€β”€ eventRoutes.js
β”‚   β”‚   └── transactionRoutes.js
β”‚   β”œβ”€β”€ server.js             # Express server
β”‚   β”œβ”€β”€ seedDatabase.js       # Database seeding
β”‚   └── package.json
β”‚
β”œβ”€β”€ smart-contract/           # Smart contracts
β”‚   β”œβ”€β”€ contracts/            # Solidity contracts
β”‚   β”‚   └── TicketNFT.sol
β”‚   β”œβ”€β”€ deploy.js             # Deployment script
β”‚   β”œβ”€β”€ hardhat.config.js     # Hardhat configuration
β”‚   β”œβ”€β”€ mint-bulk.js          # Bulk minting script
β”‚   β”œβ”€β”€ mint-test-tickets.js  # Test ticket minting
β”‚   └── package.json
β”‚
β”œβ”€β”€ index.html                # HTML template
β”œβ”€β”€ vite.config.ts            # Vite configuration
β”œβ”€β”€ tailwind.config.js        # Tailwind CSS config
β”œβ”€β”€ tsconfig.json             # TypeScript config
└── package.json              # Root package.json

🎯 Usage

For Event Attendees

  1. Connect Wallet: Click "Connect MetaMask" to link your wallet
  2. Browse Events: View available events on the Events page
  3. Purchase Tickets: Buy tickets using your connected wallet
  4. View Tickets: Check your tickets in "My Tickets" section
  5. Transfer Tickets: Transfer tickets to another wallet address
  6. Verify Tickets: Use QR codes for ticket verification at events

For Event Organizers

  1. Mint Tickets: Use the smart contract to create tickets for events
  2. Verify at Entry: Scan QR codes to validate tickets
  3. Track Sales: Monitor ticket sales through the blockchain

πŸ”‘ API Endpoints

Events

  • GET /api/events - Get all events
  • GET /api/events/:id - Get event by ID
  • POST /api/events - Create new event
  • PUT /api/events/:id - Update event
  • DELETE /api/events/:id - Delete event

Transactions

  • GET /api/transactions - Get all transactions
  • GET /api/transactions/:walletAddress - Get transactions by wallet
  • POST /api/transactions - Create new transaction

πŸ§ͺ Testing

Smart Contract Testing

cd smart-contract
npm test

Test Scripts

# Test blockchain verification
node test-blockchain-verify.js

# Check ticket status
node check-tickets.js

# Test live state
node test-live-state.js

πŸ“± Smart Contract Functions

Key Functions

  • mintTicket() - Mint a new ticket NFT
  • transferTicket() - Transfer ticket to another address
  • getTicketDetails() - Get ticket information
  • invalidateTicket() - Mark ticket as used
  • isTicketValid() - Check if ticket is valid
  • getEventTickets() - Get all tickets for an event

πŸ” Security Features

  • Blockchain Immutability: Ticket data stored on blockchain
  • Ownership Verification: Each ticket has a verified owner
  • Transfer Protection: Only owner can transfer tickets
  • Double-spending Prevention: Tickets can only be used once
  • Smart Contract Security: Built with OpenZeppelin standards

🌐 Deployment

Deploy to Polygon Mumbai Testnet

  1. Get test MATIC from Mumbai Faucet
  2. Update hardhat.config.js with your credentials
  3. Deploy contract:
npm run deploy:mumbai

Deploy Frontend

npm run build

Deploy the dist folder to:

  • Vercel
  • Netlify
  • GitHub Pages
  • Any static hosting service

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘₯ Authors

πŸ™ Acknowledgments

  • OpenZeppelin for secure smart contract templates
  • Hardhat for Ethereum development environment
  • React and Vite for modern frontend tooling
  • Tailwind CSS for styling

πŸ“ž Support

For issues and questions:

  • Open an issue on GitHub
  • Check existing documentation
  • Review the code examples

πŸ—ΊοΈ Roadmap

  • Add support for multiple blockchain networks
  • Implement ticket resale marketplace
  • Add price limits and royalties
  • Mobile app development
  • Enhanced analytics dashboard
  • Multi-language support
  • Integration with event platforms

⚠️ Disclaimer

This is an educational project. Always conduct thorough security audits before deploying smart contracts to production or handling real financial transactions.


Built with ❀️ using React, Solidity, and Web3 technologies

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages