Skip to content

aceppaluni/fitchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏋️ FitChain — Web3 Fitness E-Commerce

A decentralised fitness store built on Ethereum (Hardhat local) with smart contract escrow, order tracking, and NFT loyalty badges.


Project Structure

fitchain/
├── contracts/
│   ├── FitChainAccess.sol       # Role-based permissions (Admin, Vendor)
│   ├── ProductCatalog.sol       # Inventory: clothing, shoes, equipment
│   ├── OrderManager.sol         # Order lifecycle tracking
│   ├── Marketplace.sol          # Purchase logic + escrow + refunds
│   └── RewardsAndLoyalty.sol    # Points system + NFT member badges
├── scripts/
│   └── deploy.js                # Deploys & wires all contracts + seeds products
├── test/
│   └── fitchain.test.js         # Full test suite (Hardhat + Chai)
├── frontend/
│   └── index.html               # MetaMask-enabled storefront UI
├── hardhat.config.js
└── package.json

Quick Start

1. Install dependencies

cd fitchain
npm install

2. Compile contracts

npx hardhat compile

3. Run tests

npx hardhat test

4. Start a local Hardhat node

npx hardhat node

This prints 20 test accounts with private keys. Import one into MetaMask:

  • Network: http://127.0.0.1:8545, Chain ID: 31337

5. Deploy contracts (in a second terminal)

npx hardhat run scripts/deploy.js --network localhost

This outputs a deployment.json with all contract addresses and seeds 6 sample products.

6. Wire up the frontend

Open frontend/index.html and update the CONFIG block at the top:

const CONFIG = {
  chainId: "0x7a69",
  contracts: {
    ProductCatalog: "0xYourAddress...",
    Marketplace:    "0xYourAddress...",
    OrderManager:   "0xYourAddress...",
  }
};

Then open frontend/index.html in your browser (use a local server like npx serve frontend).


Contract Architecture

FitChainAccess
    │  (role checks for all contracts)
    ▼
ProductCatalog ◄──── Marketplace ────► OrderManager
                          │
                  ETH escrow held until shipped
                          │
                 RewardsAndLoyalty (points + NFT badges)

Deployment Order

  1. FitChainAccess — no deps
  2. ProductCatalog — needs Access address
  3. OrderManager — needs Access address
  4. RewardsAndLoyalty — needs Access address
  5. Marketplace — needs all above
  6. Call orderManager.setMarketplace() and rewards.setMarketplace()

Smart Contract Reference

Contract Key Functions
FitChainAccess addAdmin, addVendor, isAdmin, isVendor
ProductCatalog addProduct, updateProduct, deactivateProduct, getActiveProducts
OrderManager createOrder, updateStatus, getOrdersByBuyer, getOrderItems
Marketplace purchase (payable), shipAndRelease, refund, withdrawFees
RewardsAndLoyalty awardPoints, redeemPoints, getMemberInfo, availablePoints

Buy Flow (User Journey)

  1. User connects MetaMask → localhost:8545 (Hardhat)
  2. Browses products from ProductCatalog
  3. Adds items to cart → calls Marketplace.purchase() with exact ETH
  4. ETH is escrowed in the Marketplace contract
  5. Admin calls shipAndRelease() → funds sent to treasury (minus 2.5% fee)
  6. Buyer confirms delivery via OrderManager.updateStatus()
  7. Loyalty points awarded → NFT badge minted if threshold crossed

Loyalty Tiers

Tier Points Required Badge
Bronze 500 🥉 NFT minted
Silver 2,000 🥈 Badge upgraded
Gold 5,000 🥇 Badge upgraded
Platinum 15,000 💎 Badge upgraded

Moving to Production

  1. Change hardhat.config.js to add your target network (Polygon, Base, etc.)
  2. Set PRIVATE_KEY and RPC URL in a .env file (never commit this!)
  3. Replace treasury address with a multisig (e.g. Safe)
  4. Run a contract audit before mainnet deployment
  5. Deploy IPFS images for products instead of placeholder URIs

Tech Stack

  • Hardhat — local EVM, compilation, testing, deployment
  • OpenZeppelin — AccessControl, ERC721, ReentrancyGuard
  • ethers.js v6 — frontend Web3 provider
  • MetaMask — wallet connector
  • Solidity 0.8.24 — all contracts

FitChain is a local development scaffold. Audit all contracts before any mainnet deployment.

About

This is a smart contract for an e-commerce fitness platform

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors