A decentralised fitness store built on Ethereum (Hardhat local) with smart contract escrow, order tracking, and NFT loyalty badges.
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
cd fitchain
npm installnpx hardhat compilenpx hardhat testnpx hardhat nodeThis prints 20 test accounts with private keys. Import one into MetaMask:
- Network:
http://127.0.0.1:8545, Chain ID:31337
npx hardhat run scripts/deploy.js --network localhostThis outputs a deployment.json with all contract addresses and seeds 6 sample products.
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).
FitChainAccess
│ (role checks for all contracts)
▼
ProductCatalog ◄──── Marketplace ────► OrderManager
│
ETH escrow held until shipped
│
RewardsAndLoyalty (points + NFT badges)
FitChainAccess— no depsProductCatalog— needs Access addressOrderManager— needs Access addressRewardsAndLoyalty— needs Access addressMarketplace— needs all above- Call
orderManager.setMarketplace()andrewards.setMarketplace()
| 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 |
- User connects MetaMask →
localhost:8545(Hardhat) - Browses products from
ProductCatalog - Adds items to cart → calls
Marketplace.purchase()with exact ETH - ETH is escrowed in the Marketplace contract
- Admin calls
shipAndRelease()→ funds sent to treasury (minus 2.5% fee) - Buyer confirms delivery via
OrderManager.updateStatus() - Loyalty points awarded → NFT badge minted if threshold crossed
| Tier | Points Required | Badge |
|---|---|---|
| Bronze | 500 | 🥉 NFT minted |
| Silver | 2,000 | 🥈 Badge upgraded |
| Gold | 5,000 | 🥇 Badge upgraded |
| Platinum | 15,000 | 💎 Badge upgraded |
- Change
hardhat.config.jsto add your target network (Polygon, Base, etc.) - Set
PRIVATE_KEYand RPC URL in a.envfile (never commit this!) - Replace treasury address with a multisig (e.g. Safe)
- Run a contract audit before mainnet deployment
- Deploy IPFS images for products instead of placeholder URIs
- 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.