A decentralized ticket sale platform built on Ethereum (Sepolia testnet) that enables secure ticket purchasing, swapping, and reselling with automated service fee handling. The platform features a beautiful Tihar Festival-themed UI with dark/light mode support.
Tihar-Ticket-Sell/
βββ contracts/
β βββ TicketSale.sol # Smart contract
βββ pages/
β βββ _app.js # Next.js app wrapper
β βββ index.js # Main UI page
βββ styles/
β βββ globals.css # Global styles
β βββ Home.module.css # Component styles
βββ scripts/
β βββ compile.js # Contract compilation
β βββ deploy.js # Contract deployment
βββ artifacts/ # Compiled contract files
βββ .env # Environment variables
βββ config.json # Contract configuration
βββ hardhat.config.js # Hardhat configuration
βββ package.json # Project dependencies
- Solidity ^0.8.17 (Smart Contract)
- Hardhat (Development Environment)
- Ethers.js v5.7.2 (Blockchain Interaction)
- Web3Modal (Wallet Connection)
- Sepolia Testnet
- Next.js 15.0.2
- React 18.3.1
- CSS Modules
- Web3.js
- Node.js (v14 or higher)
- MetaMask wallet
- Sepolia testnet ETH
- Infura account
- Clone the repository:
git clone <repository-url>
cd Tihar-Ticket-Sell
- Install dependencies:
npm install
- Environment Setup:
Create a .env file in the root directory:
INFURA_URL=https://sepolia.infura.io/v3/YOUR_INFURA_PROJECT_ID
PRIVATE_KEY=YOUR_WALLET_PRIVATE_KEY
MANAGER_ADDRESS=YOUR_MANAGER_WALLET_ADDRESS
Where to get these values:
-
INFURA_URL:
- Sign up at infura.io
- Create new project
- Select Sepolia network
- Copy the HTTPS endpoint
-
PRIVATE_KEY:
- Open MetaMask
- Click three dots β Account Details
- Export Private Key
- Copy the key (never share this!)
-
MANAGER_ADDRESS:
- Your MetaMask wallet address
- This will be the contract manager
- Compile the contract:
npx hardhat clean
npx hardhat compile
- Deploy to Sepolia:
npx hardhat run scripts/deploy.js --network sepolia
Example output:
sajanpoudel@iPhone Ticket-Sale-Contract % npx hardhat run scripts/deploy.js --network sepolia
Deploying contracts with account: 0x60776F9B7B8F8060Bc24c1F29D46FC532a71b343
Deploying with options: {
numTickets: 100,
ticketPrice: '0.001',
gasLimit: 8000000,
gasPrice: '1774917942'
}
TicketSale deployed to: 0x408c5313592161d69Ae7acbca2A9b744FB6aBB9a
Contract deployed with:
- Number of tickets: 100
- Ticket price: 0.001 ETH
- Manager address: 0x60776F9B7B8F8060Bc24c1F29D46FC532a71b343
- Test the contract:
npx hardhat test
TicketSale Contract
Deployment
β Should set the right owner
β Should set the correct ticket price
β Should set the correct number of tickets
Ticket Purchase
β Should allow buying a ticket
β Should not allow buying with incorrect price
β Should not allow buying same ticket twice
β Should not allow buying multiple tickets
Ticket Swapping
β Should allow offering a swap
β Should allow accepting a swap
β Should not allow swap without ownership
Ticket Resale
β Should allow listing ticket for resale
β Should allow buying resale ticket
β Should transfer service fee to manager
Manager Functions
β Should allow manager to update ticket price
β Should allow manager to add tickets
β Should not allow non-manager to update price
16 passing (1s)
- Update Configuration:
After deployment, you'll get a contract address. Update these files:
config.json:
{
"contractAddress": "YOUR_DEPLOYED_CONTRACT_ADDRESS",
"numTickets": 100,
"ticketPrice": "1000000000000000",
"deployedAt": "2024-10-29T22:31:49.475Z",
"network": "sepolia",
"managerAddress": "YOUR_MANAGER_ADDRESS"
}
pages/index.js:
const contractAddress = "YOUR_DEPLOYED_CONTRACT_ADDRESS";
- Start the development server:
npm run dev
buyTicket(uint ticketId)
: Purchase a ticketgetTicketOf(address person)
: Check ticket ownershipofferSwap(uint ticketId)
: Offer to swap ticketsacceptSwap(uint ticketId)
: Accept a swap offerresaleTicket(uint price)
: List ticket for resaleacceptResale(uint ticketId)
: Buy a resale ticket
updateTicketPrice(uint newPrice)
: Update ticket priceaddTickets(uint additionalTickets)
: Add more ticketsgetTotalAvailableTickets()
: Check available tickets
- Tihar Festival theme
- Dark/light mode
- Festival animations
- Responsive design
-
Wallet Connection
- MetaMask integration
- Account display
- Network validation
-
Ticket Management
- Purchase tickets
- Swap tickets
- Resale functionality
- Ticket validation
-
Manager Dashboard
- Add tickets
- Update prices
- View statistics
-
Environment Variables
- Never commit .env file
- Keep private keys secure
- Use separate development wallet
-
Contract Security
- One ticket per address
- Manager-only functions
- Automated fee handling
-
Add Sepolia to MetaMask:
- Network Name: Sepolia Test Network
- RPC URL: https://sepolia.infura.io/v3/
- Chain ID: 11155111
- Currency Symbol: SepoliaETH
- Block Explorer: https://sepolia.etherscan.io/
-
Get Test ETH:
- Visit: https://sepoliafaucet.com/
- Connect wallet
- Request test ETH
Run the test suite:
npx hardhat test
- Build for production:
npm run build
- Start production server:
npm start
-
MetaMask Connection Issues:
- Ensure Sepolia network is selected
- Check if you have test ETH
- Clear MetaMask cache if needed
-
Transaction Failures:
- Check gas prices
- Verify contract address
- Ensure sufficient balance
-
UI Issues:
- Clear browser cache
- Check console for errors
- Verify contract connection
-
Connect Wallet Interface
- MetaMask integration
- Network validation
- Account display
-
Available Tickets Display
- Day-based categorization
- Price information
- Ticket availability status
-
Ticket Management Interface
- Owned ticket display
- Ticket details
- Management options
-
Ticket Swap Interface
- Swap offer creation
- Swap acceptance
- Current offers display
-
Ticket Resale Section
- Price setting
- Available resale tickets
- Purchase interface
-
Manager Control Panel
- Price updates
- Ticket addition
- Statistics overview
-
Dark Mode Theme
- Theme toggle
- Improved visibility
- Festival-themed elements
-
Transaction History
- Recent activities
- Transaction details
- Status tracking