A full-stack decentralized e-commerce marketplace built on Aptos blockchain with escrow-based payments, product management, and order tracking.
- Overview
- Architecture
- Smart Contract Modules
- Workflow & User Journey
- Technology Stack
- Project Structure
- Setup & Installation
- Smart Contract Deployment
- Running the Application
- Testing
This is a decentralized e-commerce platform that enables secure peer-to-peer transactions using blockchain technology. The platform features:
- Role-based system: Buyers and Sellers with distinct capabilities
- Product Management: Create, update, and manage product listings
- Secure Escrow System: Funds held in smart contracts until delivery confirmation
- Order Tracking: Complete order lifecycle management
- Custom Indexer: PostgreSQL-based indexer for fast data retrieval
- Modern UI: Next.js frontend with Aptos Wallet integration
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (Next.js) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Buyer UI β β Seller UI β β Admin UI β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββ Aptos Wallet Adapter
β
ββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββ
β Aptos Blockchain Layer β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Smart Contract Modules β β
β β ββββββββββββββββ ββββββββββββββββ β β
β β βUserProfile β β Product β β β
β β β Module β β Module β β β
β β ββββββββ¬ββββββββ ββββββββ¬ββββββββ β β
β β β β β β
β β ββββββββ΄ββββββββ ββββββββ΄ββββββββ β β
β β β Order β β Escrow β β β
β β β Module β β Module β β β
β β ββββββββββββββββ ββββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β Events: ProfileCreated, ProductCreated, OrderPlaced, β
β FundsLocked, OrderDelivered, FundsReleased β
ββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β (Blockchain Events)
β
ββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββ
β Custom Indexer (Rust + PostgreSQL) β
β - Processes blockchain events in real-time β
β - Stores indexed data for fast queries β
β - Provides REST API for frontend β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Buyer Flow:
1. Connect Wallet β 2. Register Profile (Buyer) β 3. Browse Products
4. Select Product β 5. Initiate Escrow Order β 6. Funds Locked
7. Wait for Delivery β 8. Confirm with Code β 9. Funds Released to Seller
Seller Flow:
1. Connect Wallet β 2. Register Profile (Seller) β 3. Create Products
4. Receive Orders β 5. Get Delivery Code β 6. Deliver Product
7. Enter Delivery Code β 8. Wait for Buyer Confirmation β 9. Receive Funds
Purpose: Manages user registration and profiles for buyers and sellers.
Key Features:
- User registration with role selection (Buyer/Seller)
- Profile information: name, email, country, physical address, bio
- Profile activation/deactivation
- Profile updates
Main Functions:
// Entry Functions
register_profile(sender, name, country, role, email, physical_address, bio)
update_profile(sender, name, country, email, physical_address, bio)
deactivate_profile(sender)
reactivate_profile(sender)
// View Functions
get_profile(user_addr) -> UserProfile
is_seller(user_addr) -> bool
is_buyer(user_addr) -> bool
profile_exists(user_addr) -> boolEvents Emitted:
ProfileCreatedEventProfileUpdatedEventProfileDeactivatedEventProfileReactivatedEvent
Purpose: Handles product creation, listing, inventory management, and product lifecycle.
Key Features:
- Product creation (seller-only)
- Product details: title, description, price, quantity, images, category
- Inventory management (add/reduce stock)
- Product availability toggle
- Soft delete functionality
- Global product registry
Main Functions:
// Entry Functions
create_product(sender, title, description, price, total_quantity, image_urls, category)
update_product(sender, product_obj, title, description, price, image_urls, category)
update_inventory(sender, product_obj, quantity_to_add)
reduce_inventory(sender, product_obj, quantity_to_reduce)
set_product_availability(sender, product_obj, is_available)
delete_product(sender, product_obj)
// View Functions
get_all_products() -> vector<address>
get_product(product_obj) -> (title, description, price, quantity, ...)
get_seller_products(seller_addr) -> vector<address>
is_product_available(product_obj) -> boolEvents Emitted:
ProductCreatedEventProductUpdatedEventProductDeletedEventProductAvailabilityChangedEventInventoryUpdatedEvent
Purpose: Manages order placement, tracking, and status updates.
Key Features:
- Order placement (buyer-only)
- Order status tracking (Pending β Confirmed β Processing β Shipped β Delivered)
- Order cancellation (with conditions)
- Payment tracking
- Shipping address updates
- Order history for buyers and sellers
Order Status Flow:
PENDING β CONFIRMED β PROCESSING β SHIPPED β DELIVERED
β β β
CANCELLED CANCELLED CANCELLED
DELIVERED β REFUNDED (special case)
Main Functions:
// Entry Functions
place_order(buyer, product_obj, quantity, shipping_address, notes)
update_order_status(sender, order_obj, new_status)
cancel_order(sender, order_obj, reason)
update_shipping_address(buyer, order_obj, new_shipping_address)
mark_order_paid(buyer, order_obj)
// View Functions
get_order(order_obj) -> (order_id, product, buyer, seller, quantity, ...)
get_buyer_orders(buyer_addr) -> vector<address>
get_seller_orders(seller_addr) -> vector<address>
get_order_status(order_obj) -> u8
is_order_paid(order_obj) -> boolEvents Emitted:
OrderPlacedEventOrderStatusUpdatedEventOrderCancelledEventPaymentConfirmedEvent
Purpose: Secure fund management using escrow mechanism with delivery verification codes.
Key Features:
- Escrow-based payments: Funds locked until delivery confirmation
- 6-digit delivery code: Generated for seller to mark delivery
- 4-digit receiving code: Generated for buyer to confirm receipt
- Automatic fund release: Funds transferred to seller after confirmation
- Dispute resolution: Cancel and refund before delivery
- APT coin integration: Uses AptosCoin for payments
Escrow Workflow:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ESCROW WORKFLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Step 1: INITIATE TRADE & LOCK FUNDS
ββββββββββββββββββββββββββββββββββββ
Buyer clicks "Buy Now"
β
System generates:
β’ 6-digit delivery code (for seller)
β’ 4-digit receiving code (for buyer)
β
Buyer's funds withdrawn and locked in escrow
β
Status: HOLDING
β
Events: TradeInitiatedEvent, FundsLockedEvent
Step 2: DELIVER ORDER
ββββββββββββββββββββββ
Seller ships product
β
Seller enters 6-digit delivery code
β
System validates code
β
Status: DELIVERED
β
Event: OrderDeliveredEvent
Step 3: CONFIRM DELIVERY & RELEASE FUNDS
βββββββββββββββββββββββββββββββββββββββββ
Buyer receives product
β
Buyer enters 4-digit receiving code
β
System validates code
β
Funds automatically released to seller
β
Status: COMPLETED
β
Events: DeliveryConfirmedEvent, FundsReleasedEvent
Alternative: CANCEL ORDER
ββββββββββββββββββββββββββ
Before delivery (HOLDING status)
β
Buyer or Seller can cancel
β
Funds automatically refunded to buyer
β
Status: CANCELLED
β
Event: EscrowCancelledEvent
Main Functions:
// Entry Functions
initiate_trade_and_lock_funds(buyer, product_obj, quantity, shipping_address, tx_hash)
deliver_order(seller, escrow_order_obj, delivery_code)
confirm_delivery_and_release_funds(buyer, escrow_order_obj, receiving_code)
cancel_escrow_order(sender, escrow_order_obj, reason)
// View Functions
get_escrow_order(escrow_order_obj) -> (id, product, buyer, seller, amount, codes, ...)
get_buyer_escrow_orders(buyer_addr) -> vector<address>
get_seller_escrow_orders(seller_addr) -> vector<address>
get_delivery_code(escrow_order_obj) -> String
get_receiving_code(escrow_order_obj) -> String
is_funds_locked(escrow_order_obj) -> boolEvents Emitted:
TradeInitiatedEventFundsLockedEventOrderDeliveredEventDeliveryConfirmedEventFundsReleasedEventEscrowCancelledEvent
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BUYER JOURNEY β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. REGISTRATION & SETUP
ββ Connect Aptos Wallet (Petra/Martian/Pontem)
ββ Register profile as "Buyer"
ββ Browse marketplace
2. PRODUCT SELECTION
ββ Search/filter products by category
ββ View product details (price, images, description)
ββ Check seller information
ββ Select quantity
3. CHECKOUT & PAYMENT
ββ Click "Buy Now"
ββ Enter shipping address
ββ Review order total
ββ Approve transaction in wallet
ββ Funds locked in escrow smart contract
ββ Receive 4-digit receiving code
4. ORDER TRACKING
ββ View order status in dashboard
ββ Track: Pending β Confirmed β Processing β Shipped
ββ Wait for delivery notification
5. DELIVERY CONFIRMATION
ββ Receive product
ββ Enter 4-digit receiving code
ββ Funds automatically released to seller
ββ Order marked as completed
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SELLER JOURNEY β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. REGISTRATION & SETUP
ββ Connect Aptos Wallet
ββ Register profile as "Seller"
ββ Access seller dashboard
2. PRODUCT MANAGEMENT
ββ Create new product listing
β ββ Add title, description, price
β ββ Upload images (S3 URLs)
β ββ Set category and quantity
β ββ Publish to marketplace
ββ Manage inventory (add/reduce stock)
ββ Update product details
ββ Toggle availability or delete products
3. ORDER MANAGEMENT
ββ Receive order notification
ββ View order details and buyer information
ββ Confirm order (change status to CONFIRMED)
ββ Process order (change status to PROCESSING)
ββ Receive 6-digit delivery code
4. DELIVERY & FULFILLMENT
ββ Ship product to buyer
ββ Enter 6-digit delivery code in system
ββ Order marked as DELIVERED
ββ Wait for buyer confirmation
5. PAYMENT RECEIPT
ββ Buyer confirms delivery with receiving code
ββ Smart contract releases funds automatically
ββ APT coins deposited to seller wallet
ββ Transaction completed
User Profile Module (Foundation)
β
ββββ Product Module (Sellers create products)
β β
β ββββ Order Module (Buyers place orders)
β β β
β β ββββ Status updates flow
β β
β ββββ Escrow Module (Secure payment flow)
β β
β ββββ Lock funds
β ββββ Verify delivery codes
β ββββ Release funds
β
ββββ All modules verify user roles and permissions
- Aptos Blockchain: Layer-1 blockchain using Move language
- Move Language: Smart contract programming language
- Aptos Framework: Core blockchain utilities (coin, timestamp, events, objects)
- Custom Indexer: Rust-based blockchain event indexer
- PostgreSQL: Database for indexed blockchain data
- Aptos Indexer SDK: Event streaming and processing
- Next.js 14: React framework with App Router
- TypeScript: Type-safe development
- Aptos TypeScript SDK: Blockchain interaction library
- Aptos Wallet Adapter: Multi-wallet support (Petra, Martian, Pontem)
- Tailwind CSS: Utility-first styling
- shadcn/ui: Component library
- React Query: Data fetching and caching
- Redux Toolkit: State management
- Node.js: JavaScript runtime
- Aptos CLI: Contract compilation and deployment
- Vitest: Unit testing framework
- Docker: Containerization (for indexer)
aptos-datn/
β
βββ contract/ # Smart Contracts (Move)
β βββ Move.toml # Move package configuration
β βββ sources/
β β βββ user_profile.move # User profile management
β β βββ product.move # Product management
β β βββ order.move # Order management
β β βββ escrow.move # Escrow payment system
β βββ tests/ # Move unit tests
β βββ test_ecommerce.move
β βββ test_escrow.move
β βββ test_order.move
β
βββ indexer/ # Custom Indexer (Rust)
β βββ Cargo.toml # Rust dependencies
β βββ src/
β β βββ main.rs # Indexer entry point
β β βββ processors/ # Event processors
β β βββ db_migrations/ # Database migrations
β βββ example.config.yaml # Indexer configuration
β
βββ src/ # Frontend (Next.js)
β βββ app/ # App Router pages
β β βββ page.tsx # Home page (marketplace)
β β βββ profile/ # User profile pages
β β βββ product/ # Product listing & details
β β βββ seller/ # Seller dashboard
β β β βββ products/ # Manage products
β β β βββ inventory/ # Inventory management
β β β βββ payments/ # Payment history
β β βββ checkout/ # Checkout flow
β β βββ order/ # Order tracking
β β βββ search/ # Product search
β β
β βββ components/ # Reusable UI components
β β βββ ui/ # shadcn/ui components
β β βββ WalletInfo.tsx # Wallet connection
β β βββ ProductCard.tsx # Product display
β β
β βββ lib/ # Utilities & contracts
β βββ contracts/ # Contract interaction layer
β β βββ profile.ts # Profile contract calls
β β βββ product.ts # Product contract calls
β β βββ order.ts # Order contract calls
β β βββ escrow.ts # Escrow contract calls
β βββ utils/ # Helper functions
β
βββ scripts/ # Deployment & utility scripts
β βββ move/
β βββ publish.js # Deploy contracts
β βββ compile.js # Compile contracts
β βββ test.js # Run tests
β βββ upgrade.js # Upgrade contracts
β
βββ public/ # Static assets
βββ .env.example # Environment variables template
βββ package.json # Node.js dependencies
βββ tsconfig.json # TypeScript configuration
βββ README.md # This file
- Node.js >= 18.x
- npm or yarn
- Aptos CLI (for contract deployment)
- PostgreSQL (for indexer)
- Rust (for building indexer)
git clone https://github.com/6829nkhpas/Aptos_Datn.git
cd Aptos_Datnnpm installCopy .env.example to .env and configure:
# Aptos Network Configuration
NEXT_PUBLIC_APTOS_NETWORK=testnet
NEXT_PUBLIC_MODULE_ADDRESS=0x...
# Contract Addresses
NEXT_PUBLIC_USER_PROFILE_MODULE=ecommerce_platform::user_profile
NEXT_PUBLIC_PRODUCT_MODULE=ecommerce_platform::product
NEXT_PUBLIC_ORDER_MODULE=ecommerce_platform::order
NEXT_PUBLIC_ESCROW_MODULE=ecommerce_platform::escrow
# Database (for indexer)
DATABASE_URL=postgresql://user:password@localhost:5432/aptos_ecommerce
# S3 Configuration (for image uploads)
AWS_S3_BUCKET=your-bucket-name
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-keynpm run move:compilenpm run move:testnpm run move:publishnpm run move:verifynpm run devVisit: http://localhost:3000
cd indexer
cargo run --releasenpm run move:start-nodenpm run testnpm run move:testnpm run test:coverage- β Escrow-based payment protection
- β Role-based access control
- β Delivery verification codes
- β Automated fund release
- β Cancel & refund mechanism
- β Product catalog with categories
- β Search and filter functionality
- β Seller reputation system
- β Order history tracking
- β Real-time inventory updates
- β Object-based architecture (Aptos Objects)
- β Event-driven design
- β Gas-optimized operations
- β Comprehensive error handling
- β Upgradeable contracts
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BLOCKCHAIN EVENTS FLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Smart Contracts Indexer Frontend
βββββββββββββββββ ββββββββ ββββββββ
β β β
β ProfileCreatedEvent β β
ββββββββββββββββββββββββββββββββββ β
β β Store in DB β
β ββββββββββββ β
β β β GET /users β
β β ββββββββββββββ
β β β
β ProductCreatedEvent β β
ββββββββββββββββββββββββββββββββββ β
β β Store in DB β
β ββββββββββββ β
β β β GET /products
β β ββββββββββββββ
β β β
β FundsLockedEvent β β
ββββββββββββββββββββββββββββββββββ β
β β Update order status β
β ββββββββββββ β
β β β GET /orders
β β ββββββββββββββ
β β β
β FundsReleasedEvent β β
ββββββββββββββββββββββββββββββββββ β
β β Complete transaction β
β ββββββββββββ β
β β β Notify user
β β ββββββββββββββ
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
This project is licensed under the Apache-2.0 License.
- DATN Project Team
- GitHub: @6829nkhpas
- Repository: https://github.com/6829nkhpas/Aptos_Datn
- Aptos Docs: https://aptos.dev
- Move Language: https://move-language.github.io/move/
- Aptos Wallet: https://petra.app
For questions or support, please open an issue on GitHub.
Built with β€οΈ on Aptos Blockchain