Skip to content

veyrix-Tr/VoucherHub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

70 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

VoucherHub - Decentralized Voucher Marketplace

A complete Web3 solution for creating, issuing, redeeming, and managing digital vouchers on the blockchain

License: MIT React Node.js Solidity

🌟 Overview

VoucherHub is a great decentralized platform that enables merchants to create, distribute, and manage digital vouchers and users to get and redeem them using blockchain technology. Built with modern Web3 technologies, it provides a secure, transparent, and efficient way to handle voucher transactions without intermediaries.

✨ Key Features

  • πŸͺ Merchant Registration: Secure merchant onboarding with admin approval
  • 🎟️ Voucher Creation: Create digital vouchers with custom metadata and pricing
  • πŸ” Secure Issuing: EIP712 signature-based voucher issuing system
  • πŸ’° Marketplace: Browse vouchers and approach respective merchants for purchase
  • πŸ”„ Redemption System: Easy voucher redemption with burn mechanism
  • πŸ‘¨β€πŸ’Ό Admin Dashboard: Complete admin control over merchant approvals and voucher management
  • πŸ“± Responsive UI: Modern interface built with React and Tailwind CSS

πŸ—οΈ Architecture

VoucherHub follows a modern three-tier architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend        β”‚    β”‚    Backend      β”‚    β”‚ Smart Contracts   β”‚
β”‚   (React)         │◄──►│   (Node.js)     │◄──►│   (Solidity)      β”‚
β”‚                   β”‚    β”‚                 β”‚    β”‚                   β”‚
β”‚ β€’ User Interface  β”‚    β”‚ β€’ API Server    β”‚    β”‚ β€’ VoucherERC1155  β”‚
β”‚ β€’ Web3 Integrationβ”‚    β”‚ β€’ Database      β”‚    β”‚ β€’ MerchantRegistryβ”‚
β”‚ β€’ Wallet Connect  β”‚    β”‚ β€’ Authenticationβ”‚    β”‚ β€’ OpenZeppelin    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Frontend

  • React 18.3.1 - Modern UI framework
  • Vite - Fast build tool and dev server
  • Tailwind CSS - Utility-first CSS framework
  • Ethers.js 5.8.0 - Ethereum interaction library
  • React Router - Client-side routing
  • Axios - HTTP client for API calls

Backend

  • Node.js 20.19 - JavaScript runtime
  • Express.js - Web application framework
  • MongoDB - NoSQL database
  • Mongoose - MongoDB object modeling
  • JWT - JSON Web Token authentication
  • Helmet - Security middleware

Smart Contracts

  • Solidity 0.8.20 - Smart contract language
  • Foundry - Development framework
  • OpenZeppelin - Security-audited contract libraries
  • ERC1155 - Multi-token standard
  • EIP712 - Typed structured data signing

Development Tools

  • ESLint - Code linting
  • Nodemon - Development server
  • Pinata (IPFS) - Decentralized storage & pinning service
  • Foundry - Smart contract development framework

πŸ“ Project Structure

VoucherHub/
β”‚
β”œβ”€β”€ πŸ“‚ frontend/                    # React frontend application
β”‚   β”œβ”€β”€ πŸ“‚ src/
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ Components/          # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“‚ admin/           # Admin-specific components
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“‚ common/          # Shared components
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“‚ connect/         # Wallet connection
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“‚ merchant/        # Merchant dashboard
β”‚   β”‚   β”‚   └── πŸ“‚ user/            # User interface
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ Context/             # React context providers
β”‚   β”‚   β”‚   β”œβ”€β”€ RoleContext.jsx     # User role management
β”‚   β”‚   β”‚   └── WalletContext.jsx   # Web3 wallet integration
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ Pages/               # Application pages
β”‚   β”‚   β”‚   β”œβ”€β”€ AdminPage.jsx       # Admin dashboard
β”‚   β”‚   β”‚   β”œβ”€β”€ ConnectPage.jsx     # Wallet connection page
β”‚   β”‚   β”‚   β”œβ”€β”€ Marketplace.jsx     # Voucher marketplace
β”‚   β”‚   β”‚   β”œβ”€β”€ MerchantPage.jsx    # Merchant dashboard
β”‚   β”‚   β”‚   └── UserPage.jsx        # User dashboard
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ utils/               # Utility functions & services
β”‚   β”‚   β”‚   β”œβ”€β”€ eip712.js           # EIP712 signature utilities
β”‚   β”‚   β”‚   β”œβ”€β”€ fetchVouchers.js    # Voucher data fetching
β”‚   β”‚   β”‚   β”œβ”€β”€ ipfs.js             # IPFS integration
β”‚   β”‚   β”‚   β”œβ”€β”€ roleDetection.js    # User role detection
β”‚   β”‚   β”‚   └── utilsMerchantRequests.js # Merchant request utilities
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ App.jsx                 # Main application component
β”‚   β”‚   β”œβ”€β”€ main.jsx                # Application entry point
β”‚   β”‚   └── index.css               # Global styles
β”‚   β”‚
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.js
β”‚
β”œβ”€β”€ πŸ“‚ backend/                     # Express.js backend server
β”‚   β”œβ”€β”€ πŸ“‚ src/
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ config/              # Configuration files
β”‚   β”‚   β”‚   └── db.js               # Database connection setup
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ controllers/         # Request handlers
β”‚   β”‚   β”‚   β”œβ”€β”€ merchantRequestController.js # Merchant request logic
β”‚   β”‚   β”‚   └── voucherController.js # Voucher CRUD operations
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ middleware/          # Authentication & validation
β”‚   β”‚   β”‚   β”œβ”€β”€ authMiddleware.js   # JWT authentication
β”‚   β”‚   β”‚   └── validateVoucher.js  # Voucher validation
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ models/              # Database models
β”‚   β”‚   β”‚   β”œβ”€β”€ MerchantRequest.js  # Merchant request schema
β”‚   β”‚   β”‚   └── Voucher.js          # Voucher schema
β”‚   β”‚   β”‚
β”‚   β”‚   └── πŸ“‚ routes/              # API routes
β”‚   β”‚       β”œβ”€β”€ merchantRequestRoutes.js # Merchant request endpoints
β”‚   β”‚       └── voucherRoutes.js    # Voucher endpoints
β”‚   β”‚
β”‚   β”œβ”€β”€ package.json
β”‚   └── server.js                   # Express server entry point
β”‚
β”œβ”€β”€ πŸ“‚ contracts/                   # Smart contracts
β”‚   β”œβ”€β”€ πŸ“‚ src/                     # Solidity contracts
β”‚   β”‚   β”œβ”€β”€ VoucherERC1155.sol      # Main voucher contract (ERC1155)
β”‚   β”‚   └── MerchantRegistry.sol    # Merchant registration & management
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ“‚ script/                  # Deployment scripts
β”‚   β”œβ”€β”€ πŸ“‚ test/                    # Contract tests
β”‚   └── foundry.toml                # Foundry configuration
β”‚
β”œβ”€β”€ πŸ“‚ spec/                        # Project specifications
└── README.md                       # Project documentation

πŸš€ Quick Start

Prerequisites

  • Node.js (v20.19 or higher)
  • npm or yarn
  • Git
  • MetaMask or compatible Web3 wallet
  • MongoDB (local or cloud instance)
  • Pinata Account (for IPFS storage)

Installation

  1. Clone the repository

    git clone https://github.com/veyrix-Tr/VoucherHub.git
    cd VoucherHub
  2. Install dependencies for all components

    # Install frontend dependencies
    cd frontend
    npm install
    
    # Install backend dependencies
    cd ../backend
    npm install
    
    # Install contract dependencies
    cd ../contracts
    forge install
    forge build
  3. Environment Setup

    Frontend (.env)

    VITE_BACKEND_URL=http://localhost:5000
    VITE_CHAIN_ID=11155111
    VITE_PINATA_JWT=your_pinata_jwt_token
    VITE_PINATA_GATEWAY=https://gateway.pinata.cloud

    Backend (.env)

    PORT=5000
    MONGODB_URI=mongodb://localhost:27017/voucherhub
    JWT_SECRET=your_jwt_secret_key # Note: JWT authentication currently disabled for development
    RPC_URL=your_rpc_url
    CHAIN_ID=11155111
  4. Start the servers

    Terminal 1 - Backend

    cd backend
    npm run dev

    Terminal 2 - Frontend

    cd frontend
    npm run dev

πŸ“‹ Smart Contract Details

VoucherERC1155

The main contract that handles voucher creation, minting, and redemption.

Key Functions:

  • mintFromVoucher() - Mint vouchers using EIP712 signatures
  • burnForRedeem() - Redeem and burn vouchers
  • setVoucherApproval() - Admin approval for voucher creation
  • issueVoucherToUser() - Direct voucher issuance by merchants

MerchantRegistry

Manages merchant registration and verification.

Key Functions:

  • registerMerchant() - Register new merchants (admin only)
  • updateMerchantStatus() - Activate/deactivate merchants
  • isMerchant() - Check if address is an active merchant

πŸ”„ Voucher Lifecycle

  1. Merchant Registration - Merchants submit registration requests through the platform
  2. Admin Approval - Admins review and approve/reject merchant applications
  3. Voucher Creation - Approved merchants create vouchers with EIP712 signatures
  4. Voucher Approval - Admins approve vouchers before users can mint them
  5. Voucher Distribution - Users mint approved vouchers; merchants may also issue them directly to users.
  6. Voucher Usage - Users approach merchants to use their vouchers
  7. Voucher Redemption - Users redeem vouchers, which burns the tokens permanently

🎯 User Roles

πŸ‘€ Regular Users

  • Browse marketplace
  • Purchase vouchers
  • Redeem vouchers
  • View transaction history

πŸͺ Merchants

  • Create voucher listings
  • Manage voucher inventory
  • Track sales and redemptions
  • Update voucher metadata

πŸ‘¨β€πŸ’Ό Admins

  • Approve/reject merchant applications
  • Approve/reject voucher listings
  • Monitor platform activity
  • Manage system settings

πŸ”§ API Endpoints

Voucher Routes

GET    /api/vouchers              # Get all vouchers
POST   /api/vouchers              # Create new voucher
GET    /api/vouchers/:id          # Get voucher by ID
PUT    /api/vouchers/:id/approve  # Approve voucher (admin only)
PUT    /api/vouchers/:id/reject   # Reject voucher (admin only)
PUT    /api/vouchers/:id/redeem   # Redeem voucher
PUT    /api/vouchers/:id/minted   # Update minted count

Merchant Request Routes

POST   /api/merchant-requests     # Submit merchant application
GET    /api/merchant-requests/me  # Get my merchant request
GET    /api/merchant-requests     # Get all requests (admin only)
PUT    /api/merchant-requests/:id/approve # Approve merchant (admin only)
PUT    /api/merchant-requests/:id/reject  # Reject merchant (admin only)

πŸ§ͺ Testing

Smart Contract Tests

cd contracts
forge test -vv

πŸš€ Deployment

Backend (Production)

cd backend
npm start

Frontend (Production)

cd frontend
npm run build
npm run preview

πŸ“„ License

This project is licensed under the MIT License.

πŸ†˜ Support

If you encounter any issues or have questions:

πŸ™ Acknowledgments

  • OpenZeppelin for secure smart contract libraries
  • The Ethereum community for Web3 standards
  • React and Node.js communities for excellent frameworks

Made with ❀️ by the veyrix-Tr [Chirag Goyal]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors