Skip to content

6829nkhpas/Aptos_Datn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Aptos E-commerce Platform (DATN)

A full-stack decentralized e-commerce marketplace built on Aptos blockchain with escrow-based payments, product management, and order tracking.

πŸ“‹ Table of Contents


🎯 Overview

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

πŸ—οΈ Architecture

System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     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                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

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

πŸ“œ Smart Contract Modules

1. User Profile Module (user_profile.move)

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) -> bool

Events Emitted:

  • ProfileCreatedEvent
  • ProfileUpdatedEvent
  • ProfileDeactivatedEvent
  • ProfileReactivatedEvent

2. Product Module (product.move)

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) -> bool

Events Emitted:

  • ProductCreatedEvent
  • ProductUpdatedEvent
  • ProductDeletedEvent
  • ProductAvailabilityChangedEvent
  • InventoryUpdatedEvent

3. Order Module (order.move)

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) -> bool

Events Emitted:

  • OrderPlacedEvent
  • OrderStatusUpdatedEvent
  • OrderCancelledEvent
  • PaymentConfirmedEvent

4. Escrow Module (escrow.move)

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) -> bool

Events Emitted:

  • TradeInitiatedEvent
  • FundsLockedEvent
  • OrderDeliveredEvent
  • DeliveryConfirmedEvent
  • FundsReleasedEvent
  • EscrowCancelledEvent

πŸ”„ Workflow & User Journey

Complete Purchase Flow with Escrow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    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

Module Interaction Flow

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

πŸ› οΈ Technology Stack

Blockchain Layer

  • Aptos Blockchain: Layer-1 blockchain using Move language
  • Move Language: Smart contract programming language
  • Aptos Framework: Core blockchain utilities (coin, timestamp, events, objects)

Backend

  • Custom Indexer: Rust-based blockchain event indexer
  • PostgreSQL: Database for indexed blockchain data
  • Aptos Indexer SDK: Event streaming and processing

Frontend

  • 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

Development Tools

  • Node.js: JavaScript runtime
  • Aptos CLI: Contract compilation and deployment
  • Vitest: Unit testing framework
  • Docker: Containerization (for indexer)

πŸ“ Project Structure

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

πŸš€ Setup & Installation

Prerequisites

  • Node.js >= 18.x
  • npm or yarn
  • Aptos CLI (for contract deployment)
  • PostgreSQL (for indexer)
  • Rust (for building indexer)

1. Clone Repository

git clone https://github.com/6829nkhpas/Aptos_Datn.git
cd Aptos_Datn

2. Install Dependencies

npm install

3. Environment Setup

Copy .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-key

πŸ“ Smart Contract Deployment

1. Compile Contracts

npm run move:compile

2. Run Tests

npm run move:test

3. Deploy to Testnet

npm run move:publish

4. Verify Deployment

npm run move:verify

▢️ Running the Application

Start Frontend Development Server

npm run dev

Visit: http://localhost:3000

Start Custom Indexer

cd indexer
cargo run --release

Start Local Aptos Node (Optional)

npm run move:start-node

πŸ§ͺ Testing

Run Frontend Tests

npm run test

Run Contract Tests

npm run move:test

Run Tests with Coverage

npm run test:coverage

πŸ”‘ Key Features

Security Features

  • βœ… Escrow-based payment protection
  • βœ… Role-based access control
  • βœ… Delivery verification codes
  • βœ… Automated fund release
  • βœ… Cancel & refund mechanism

Marketplace Features

  • βœ… Product catalog with categories
  • βœ… Search and filter functionality
  • βœ… Seller reputation system
  • βœ… Order history tracking
  • βœ… Real-time inventory updates

Smart Contract Features

  • βœ… Object-based architecture (Aptos Objects)
  • βœ… Event-driven design
  • βœ… Gas-optimized operations
  • βœ… Comprehensive error handling
  • βœ… Upgradeable contracts

πŸ“Š Event Flow Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              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
     β”‚                                β”‚            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“„ License

This project is licensed under the Apache-2.0 License.


πŸ‘₯ Authors


πŸ”— Links


πŸ“ž Support

For questions or support, please open an issue on GitHub.


Built with ❀️ on Aptos Blockchain

About

Decentralised autonomous trade network build on aptos blockchain

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors