Skip to content

Franklin1312/ChainPass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎟 ChainPass β€” NFT Event Ticketing Platform

A full-stack Web3 ticketing platform where event tickets are minted as ERC-721 NFTs on Ethereum Sepolia testnet. Secure, transparent, and scalable β€” powered by smart contracts, a Node.js backend, and a React frontend with MetaMask integration.

License Solidity Network React Node.js MongoDB


✨ Features

  • 🎫 NFT Tickets β€” Each ticket is a unique ERC-721 token minted on-chain
  • πŸ’³ MetaMask Integration β€” Connect wallet, buy tickets, and sign transactions
  • πŸ“· QR Code Validation β€” Real camera scanning for entry gate validation
  • πŸ” Owner Controls β€” Create events, deactivate sales, withdraw revenue
  • πŸ“‘ Live Blockchain Sync β€” WebSocket listener keeps MongoDB in sync with on-chain events
  • 🌐 REST API β€” Full backend API for events, tickets, and validation
  • 🎨 Sleek Dark UI β€” Space Grotesk font, gold accents, glassmorphism design

πŸ— Tech Stack

Layer Technology
Smart Contract Solidity, ERC-721, OpenZeppelin
Development Hardhat, Ethers.js v6
Blockchain Ethereum Sepolia Testnet
Backend Node.js, Express.js, MongoDB, Mongoose
Blockchain Listener Ethers.js WebSocket Provider
Frontend React 18, React Router v6
Wallet Ethers.js v6, MetaMask
QR Codes html5-qrcode, QR Server API
Styling CSS-in-JS, Space Grotesk, Material Icons

πŸ“ Project Structure

detickets/
β”‚
β”œβ”€β”€ hardhat.config.js
β”œβ”€β”€ .env                             ← Hardhat env vars
β”‚
β”œβ”€β”€ contracts/
β”‚   └── Deticket.sol                 ← ERC-721 smart contract
β”‚
β”œβ”€β”€ scripts/
β”‚   └── deploy.js                    ← Hardhat deployment script
β”‚
β”œβ”€β”€ artifacts/                       ← Auto-generated by Hardhat compile
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ index.js                     ← Express server entry point
β”‚   β”œβ”€β”€ .env                         ← Backend environment variables
β”‚   β”œβ”€β”€ abi/
β”‚   β”‚   └── EventTicketPlatform.json ← Contract ABI (copy from artifacts)
β”‚   β”œβ”€β”€ db/
β”‚   β”‚   └── connect.js               ← MongoDB connection
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ Event.js
β”‚   β”‚   └── Ticket.js
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ events.js
β”‚   β”‚   β”œβ”€β”€ tickets.js
β”‚   β”‚   └── validate.js
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── listener.js              ← Real-time blockchain event listener
β”‚   └── scripts/
β”‚       β”œβ”€β”€ syncEvents.js            ← Manually sync missed events
β”‚       └── syncTickets.js           ← Manually sync missed tickets
β”‚
└── frontend/
    β”œβ”€β”€ package.json
    └── src/
        β”œβ”€β”€ App.js
        β”œβ”€β”€ index.js
        β”œβ”€β”€ index.css
        β”œβ”€β”€ abi/
        β”‚   └── EventTicketPlatform.json ← Contract ABI (copy from artifacts)
        β”œβ”€β”€ context/
        β”‚   └── WalletContext.js     ← Global MetaMask + contract state
        β”œβ”€β”€ components/
        β”‚   └── Sidebar.js           ← Navigation sidebar
        └── pages/
            β”œβ”€β”€ EventList.js         ← Homepage
            β”œβ”€β”€ BuyTicket.js         ← Purchase + mint ticket
            β”œβ”€β”€ MyTickets.js         ← View owned NFT tickets
            β”œβ”€β”€ AdminPanel.js        ← Owner dashboard
            └── QRScanner.js         ← Camera QR entry validation

πŸš€ Getting Started

Prerequisites


1. Clone the repository

git clone https://github.com/yourusername/detickets.git
cd detickets

2. Install dependencies

# Root β€” Hardhat
npm install

# Backend
cd backend && npm install

# Frontend
cd ../frontend && npm install

3. Configure environment variables

Root .env

PRIVATE_KEY=your_deployer_wallet_private_key
RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY
API_KEY=your_etherscan_api_key

backend/.env

MONGO_URI=mongodb://localhost:27017/detickets
RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY
WS_RPC_URL=wss://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY
CONTRACT_ADDRESS=0xYOUR_DEPLOYED_CONTRACT_ADDRESS
OWNER_PRIVATE_KEY=your_deployer_wallet_private_key
PORT=3001

4. Compile and deploy the contract

npx hardhat compile
npx hardhat run scripts/deploy.js --network sepolia

Copy the printed contract address and update CONTRACT_ADDRESS in backend/.env and frontend/src/context/WalletContext.js.

5. Copy the ABI

# Windows
cp artifacts\contracts\Deticket.sol\EventTicketPlatform.json backend\abi\EventTicketPlatform.json
cp artifacts\contracts\Deticket.sol\EventTicketPlatform.json frontend\src\abi\EventTicketPlatform.json

6. Start backend

cd backend
npm run dev
# βœ… MongoDB connected
# πŸ”— Blockchain listener started
# πŸš€ Server running on http://localhost:3001

7. Start frontend

cd frontend
npm start
# Opens at http://localhost:3000

🌐 API Reference

Method Endpoint Description
GET /api/events Get all events
GET /api/events/active Get active events only
GET /api/events/:eventId Get single event with tickets
GET /api/tickets/:tokenId Get single ticket
GET /api/tickets/owner/:address Get tickets by wallet address
GET /api/validate/:tokenId Check ticket validity status
POST /api/validate Validate ticket + mark used on-chain

🧭 Pages

Page URL Access Description
Events / Everyone Browse all upcoming events
Buy Ticket /events/:id MetaMask required Mint an NFT ticket
My Tickets /my-tickets Connected wallet View tickets + QR codes
Admin Panel /admin Owner wallet only Create events, withdraw revenue
QR Scanner /scanner Owner wallet only Validate tickets at entry gate

πŸ”„ Full User Flow

Owner creates event β†’ Admin Panel
        ↓
Event saved on-chain + synced to MongoDB via listener
        ↓
User connects MetaMask β†’ buys ticket β†’ pays ETH
        ↓
ERC-721 NFT minted to user's wallet on Sepolia
        ↓
Listener saves ticket to MongoDB automatically
        ↓
User opens My Tickets β†’ reveals QR code image
        ↓
Owner opens QR Scanner β†’ scans QR with camera
        ↓
Ticket validated on-chain β†’ permanently marked as used
        ↓
Owner withdraws accumulated ETH from Admin Panel

πŸ“¦ Smart Contract

Deployed on Sepolia: 0x69a25A22F86b375ae79D756B37b721EfEf4FC574

Function Description Access
createEvent(name, date, venue, price, supply, maxResalePct) Create a new ticketed event Owner only
mintTicket(eventId, seat, metadataURI, buyer) Mint an NFT ticket Public (payable)
deactivateEvent(eventId) Stop ticket sales Owner only
markTicketAsUsed(tokenId, qrHash) Validate and consume a ticket Owner only
withdrawRevenue() Withdraw accumulated platform fees Owner only
getEventDetails(eventId) Read event info Public

πŸ›  Utility Scripts

Run these if the listener missed events while the backend was offline:

cd backend
node scripts/syncEvents.js    # sync all on-chain events to MongoDB
node scripts/syncTickets.js   # sync all on-chain tickets to MongoDB

🦊 MetaMask Setup

1. Open MetaMask β†’ click network dropdown
2. Add Network β†’ search "Sepolia Testnet" β†’ Add
3. Get free test ETH from https://sepoliafaucet.com
4. Connect wallet on the DeTickets site

🀝 Contributing

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

πŸ“„ License

This project is licensed under the MIT License. See LICENSE for details.


πŸ™ Acknowledgements


Built with ❀️ on Ethereum

About

ChainPass is a decentralized NFT-based ticketing platform built on blockchain, enabling secure minting, resale, and QR-based event verification.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages