A modern, decentralized e-commerce platform that combines traditional web technologies with blockchain capabilities. Built with the MERN stack and integrated with Ethereum blockchain for secure cryptocurrency payments via MetaMask.
- Features
- Tech Stack
- Blockchain Integration
- Architecture
- Setup Instructions
- Usage Guide
- Smart Contract Details
- API Documentation
- Security Considerations
- License
- π Secure Authentication - Email/password and Google OAuth integration
- π¦ MetaMask Wallet Integration - Connect and manage Ethereum wallets
- π° Cryptocurrency Payments - Accept ETH payments with real-time conversion
- π Shopping Cart - Full-featured cart with quantity management
- π¦ Product Catalog - Browse and search products with detailed views
- π Blockchain Transaction Tracking - All payments recorded on-chain
- π± Responsive Design - Beautiful UI with Bootstrap 5 and custom styling
- π€ User Profiles - Manage account and wallet connection status
- π¬ AI Chatbot - Integrated customer support assistant
- π Order Management - Track orders with blockchain verification
| Technology | Version | Purpose |
|---|---|---|
| React | 18.3.1 | Core UI framework for building component-based interface |
| React Router DOM | 6.x | Client-side routing and navigation |
| Bootstrap | 5.3.x | Responsive UI components and styling |
| React Bootstrap | 2.x | React components for Bootstrap |
| Ethers.js | 6.x | Ethereum blockchain interaction library |
| Axios | 1.x | HTTP client for API requests |
| JavaScript (ES6+) | - | Primary programming language |
| Technology | Version | Purpose |
|---|---|---|
| Node.js | 16+ | JavaScript runtime environment |
| Express.js | 4.x | Web application framework |
| MongoDB | 5.x | NoSQL database for storing user and product data |
| Mongoose | 7.x | MongoDB object modeling and schema validation |
| JWT | 9.x | JSON Web Tokens for authentication |
| bcryptjs | 2.x | Password hashing and security |
| CORS | 2.x | Cross-Origin Resource Sharing middleware |
| dotenv | 16.x | Environment variable management |
| JavaScript (Node.js) | - | Server-side programming language |
| Technology | Version | Purpose |
|---|---|---|
| Solidity | 0.8.x | Smart contract programming language |
| Hardhat | 2.x | Ethereum development environment |
| Ethers.js | 6.x | Ethereum library for wallet and contract interaction |
| MetaMask | - | Browser extension for Ethereum wallet management |
| Ethereum | - | Blockchain network for decentralized transactions |
- Git - Version control
- npm - Package management
- VS Code - Code editor
- Postman - API testing
- MongoDB Compass - Database management
This platform leverages Ethereum blockchain technology to provide transparent, secure, and immutable payment processing. Unlike traditional e-commerce platforms that rely solely on centralized payment processors, our system records transactions directly on the blockchain.
User β MetaMask Extension β Ethereum Network β Smart Contract
- Users connect their MetaMask wallet to the application
- The wallet address serves as a unique identifier
- No private keys are ever stored or transmitted
- Connection is maintained through browser session
Traditional Payment Flow:
User β Payment Gateway β Bank β Merchant
(3-5 days settlement, fees 2-3%)
Blockchain Payment Flow:
User β MetaMask β Ethereum Network β Smart Contract β Merchant Wallet
(Minutes settlement, gas fees only)
Step-by-Step Process:
-
Order Creation
- User adds products to cart
- System calculates total in USD and converts to ETH
- Real-time exchange rate ensures accurate pricing
-
Payment Initiation
- User clicks "Pay Now" with crypto payment method
- If wallet not connected, automatic connection prompt appears
- MetaMask popup shows transaction details
-
Smart Contract Execution
function createOrder(string[] memory productIds) public payable returns (uint256)
- Smart contract receives payment and product IDs
- Generates unique order ID on-chain
- Emits OrderCreated event for tracking
- Funds transferred to merchant wallet
-
Transaction Confirmation
- Ethereum network validates transaction (15-30 seconds)
- Transaction hash generated as proof
- Order recorded in both database and blockchain
-
Verification
- Transaction hash can be verified on Etherscan
- Immutable record of purchase
- Full transparency and traceability
Contract: EcommercePayment.sol
// Core functionality
- createOrder(): Process payment and create order
- getOrder(): Retrieve order details
- getOrdersByBuyer(): Get user's order history
- Events: OrderCreated, OrderStatusUpdatedKey Features:
- Immutability: Orders cannot be altered once recorded
- Transparency: All transactions publicly verifiable
- Security: Funds directly transferred, no intermediary custody
- Traceability: Complete audit trail on blockchain
On-Chain (Blockchain):
- Order ID
- Buyer wallet address
- Total amount in ETH
- Timestamp
- Product IDs
- Transaction hash
Off-Chain (MongoDB):
- Product details (name, description, images)
- User profiles and authentication
- Order metadata
- Shopping cart state
Why Hybrid Approach?
- Cost Efficiency: Storing large data on blockchain is expensive
- Performance: Database queries are faster than blockchain reads
- Flexibility: Can update product details without blockchain transactions
- Privacy: Personal information not exposed on public blockchain
Blockchain Security:
- β Decentralization: No single point of failure
- β Cryptographic Security: Transactions signed with private keys
- β Immutability: Cannot alter transaction history
- β Transparency: All transactions publicly auditable
- β No Chargebacks: Irreversible transactions prevent fraud
Application Security:
- β JWT Authentication: Secure user sessions
- β Password Hashing: bcrypt encryption
- β HTTPS: Encrypted data transmission
- β Input Validation: Prevent injection attacks
- β CORS Protection: Controlled API access
What are Gas Fees? Gas fees are transaction costs paid to Ethereum miners for processing and validating transactions.
Optimization Strategies:
- Batch multiple products in single transaction
- Use efficient Solidity code patterns
- Deploy on Layer 2 solutions (Polygon, Arbitrum) for lower fees
- Provide gas estimation before transaction
Typical Costs:
- Ethereum Mainnet: $5-50 per transaction (varies with network congestion)
- Polygon Network: $0.01-0.10 per transaction
- Testnet: Free (for development)
The platform can be deployed on:
- Ethereum Mainnet: Production, highest security
- Ethereum Testnets: Sepolia, Goerli (development/testing)
- Polygon: Lower fees, faster transactions
- Binance Smart Chain: Alternative with lower costs
- Arbitrum/Optimism: Layer 2 scaling solutions
Users can verify their transactions on blockchain explorers:
Etherscan (Ethereum):
https://etherscan.io/tx/[TRANSACTION_HASH]
Information Available:
- Transaction status (Success/Failed)
- Block number and confirmations
- From/To addresses
- Amount transferred
- Gas fees paid
- Timestamp
- Input data (order details)
| Feature | Traditional | Blockchain-Based |
|---|---|---|
| Settlement Time | 3-5 business days | Minutes |
| Transaction Fees | 2-3% + fixed fee | Gas fees only (~$1-10) |
| Chargebacks | Possible (fraud risk) | Not possible |
| International | Complex, high fees | Borderless, same cost |
| Transparency | Limited | Fully transparent |
| Intermediaries | Banks, processors | None (peer-to-peer) |
| Censorship | Possible | Resistant |
| Privacy | Data collected | Pseudonymous |
- Digital Goods: Instant delivery with blockchain proof
- International Sales: No currency conversion fees
- High-Value Items: Immutable proof of purchase
- Subscription Services: Automated recurring payments
- Marketplace: Trustless escrow between buyers/sellers
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React) β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β Pages β βComponentsβ β Context β β Utils β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β HTTP/REST API
ββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββ
β Backend (Express) β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β Routes β β Models β β Auth β β API β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
ββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββ
β β
β Mongoose β Ethers.js
βΌ βΌ
βββββββββββββββββββ ββββββββββββββββββββββββ
β MongoDB β β Ethereum Blockchain β
β (Database) β β (Smart Contract) β
βββββββββββββββββββ ββββββββββββββββββββββββ
β²
β MetaMask
β
ββββββββββ΄ββββββββββ
β User Wallet β
ββββββββββββββββββββ
- User Authentication: JWT tokens stored in localStorage
- Product Browsing: REST API fetches from MongoDB
- Cart Management: React Context API (client-side state)
- Payment: Ethers.js β MetaMask β Ethereum β Smart Contract
- Order Recording: Blockchain (immutable) + MongoDB (queryable)
- Node.js v16 or higher
- MongoDB v5 or higher
- MetaMask browser extension
- Git
git clone <repository-url>
cd chaincommerce-platform# Navigate to server directory
cd server
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Edit .env with your configuration
nano .envEnvironment Variables:
PORT=5001
MONGODB_URI=mongodb://localhost:27017/chaincommerce
JWT_SECRET=your-super-secret-jwt-key-change-this
NODE_ENV=development# Start MongoDB
mongod
# Seed database with sample products
npm run seed
# Start server
npm run devServer runs at: http://localhost:5001
# Navigate to client directory
cd client
# Install dependencies
npm install
# Start React app
npm startTo make local setup simpler for frontend-focused contributors, npm install at the project root now installs the frontend dependencies only (it runs npm install inside the client folder).
- Run frontend install from the project root:
npm install- Start both backend and frontend together from the project root:
npm start- Developer tooling (Hardhat, toolbox, etc.) has been moved into
dev-toolsso the root install stays lightweight. To install developer tools, run:
cd dev-tools; npm installNotes:
- The root
package.jsonis markedprivateand intentionally keeps the default root install focused on the client. If you need to run smart-contract tasks (compile/test/deploy), install dev tools indev-toolsfirst.
App opens at: `http://localhost:3000`
### **4. Smart Contract Setup (Optional)**
```bash
# Install Hardhat dependencies
npm install
# Compile contracts
npx hardhat compile
# Deploy to local network
npx hardhat node
npx hardhat run scripts/deploy.js --network localhost
# Deploy to testnet (Sepolia)
npx hardhat run scripts/deploy.js --network sepolia
# Update contract address in client/src/utils/contractHelper.js
- Install MetaMask extension
- Create or import wallet
- Add test network (if using testnet)
- Get test ETH from faucet: https://sepoliafaucet.com/
-
Sign Up/Sign In
- Create account with email/password or Google
- Secure authentication with JWT
-
Browse Products
- View product catalog
- Filter by category
- See prices in USD and ETH
-
Shopping Cart
- Add products to cart
- Adjust quantities
- View total in both currencies
-
Checkout
- Select payment method (Crypto/Card/PayPal)
- For crypto: Connect MetaMask wallet
- Confirm transaction
- Receive order confirmation
-
Profile Management
- View account details
- Check wallet connection status
- See wallet balance
- Manage settings
Add New Products:
POST /api/products
{
"name": "Product Name",
"description": "Description",
"priceUsd": 999.99,
"priceEth": 0.5,
"category": "Electronics",
"image": "https://example.com/image.jpg",
"stock": 50
}Deploy Smart Contract:
npx hardhat run scripts/deploy.js --network <network-name>Run Tests:
# Backend tests
cd server && npm test
# Smart contract tests
npx hardhat test
# Frontend tests
cd client && npm testLocation: contracts/EcommercePayment.sol
Functions:
// Create new order with payment
function createOrder(string[] memory productIds)
public payable returns (uint256)
// Get order details
function getOrder(uint256 orderId)
public view returns (Order memory)
// Get all orders by buyer
function getOrdersByBuyer(address buyer)
public view returns (uint256[] memory)
// Update order status (owner only)
function updateOrderStatus(uint256 orderId, OrderStatus status)
public onlyOwnerEvents:
event OrderCreated(
uint256 indexed orderId,
address indexed buyer,
uint256 amount,
uint256 timestamp
);
event OrderStatusUpdated(
uint256 indexed orderId,
OrderStatus status
);Security Features:
- ReentrancyGuard protection
- Owner-only administrative functions
- Input validation
- Safe math operations
POST /api/auth/signup
POST /api/auth/signin
POST /api/auth/google-signin
GET /api/products - Get all products
GET /api/products/:id - Get single product
POST /api/products - Create product (admin)
PUT /api/products/:id - Update product (admin)
DELETE /api/products/:id - Delete product (admin)
POST /api/orders - Create new order
GET /api/orders - Get user's orders
GET /api/orders/:id - Get order details
- β Password hashing with bcrypt
- β JWT token authentication
- β CORS protection
- β Input validation and sanitization
- β Environment variable protection
- β HTTPS in production
- β Rate limiting on API endpoints
- β MongoDB injection prevention
- β XSS protection
- β Private keys never leave MetaMask
- β Transaction signing client-side
- β Smart contract audited patterns
- β ReentrancyGuard implementation
- β Access control modifiers
- Always test on testnet first
- Use hardware wallet for large amounts
- Verify contract addresses
- Check gas prices before transactions
- Keep private keys secure
- Regular security audits
MIT License - feel free to use this project for learning and commercial purposes.
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and questions:
- Create an issue on GitHub
- Check existing documentation
- Review smart contract code
- Multi-currency support (BTC, USDT, etc.)
- NFT integration for digital products
- Decentralized storage (IPFS) for product images
- Layer 2 scaling solutions
- Mobile app (React Native)
- Admin dashboard
- Order tracking system
- Review and rating system
- Wishlist functionality
- Advanced search and filters
βοΈποΈ ChainCommerce - Built with β€οΈ using React, Node.js, MongoDB, and Ethereum
