This directory contains the Solidity smart contracts for the Chilly decentralized order tracking dApp.
The main smart contract that handles all order-related operations on-chain.
Key Features:
- ✅ Order creation with escrow payment
- ✅ Order status management (Pending → Confirmed → Processing → Shipped → Delivered)
- ✅ Dispute resolution system
- ✅ Automatic payment release on delivery
- ✅ Automatic refund on cancellation
- ✅ Platform fee management
- ✅ Multi-network support
- ✅ Gas-optimized design
Pending → Confirmed → Processing → Shipped → Delivered
↓ ↓ ↓
Cancelled Cancelled Disputed
- Order Creation: Buyer sends payment to contract (held in escrow)
- Platform Fee: Fee is deducted and sent to contract owner
- Delivery: Payment is automatically released to seller
- Cancellation: Full refund (minus platform fee) to buyer
cd contracts
npm installCreate a .env file in the contracts directory:
# Private key of deployer account (NEVER commit this!)
PRIVATE_KEY=your_private_key_here
# RPC URLs
SEPOLIA_RPC_URL=https://sepolia.infura.io/v3/YOUR_PROJECT_ID
MAINNET_RPC_URL=https://mainnet.infura.io/v3/YOUR_PROJECT_ID
POLYGON_RPC_URL=https://polygon-rpc.com
ARBITRUM_RPC_URL=https://arb1.arbitrum.io/rpc
# API Keys for contract verification
ETHERSCAN_API_KEY=your_etherscan_api_key
POLYGONSCAN_API_KEY=your_polygonscan_api_key
ARBISCAN_API_KEY=your_arbiscan_api_keynpm run compilenpm run deploy:sepolianpm run deploy:mainnetnpm run deploy:polygonnpm run deploy:arbitrumcreateOrder()- Create a new order with paymentconfirmOrder()- Seller confirms the orderupdateOrderStatus()- Update order statusmarkAsProcessing()- Mark order as processingmarkAsShipped()- Mark order as shippedaddTrackingNumber()- Add shipping tracking numbercancelOrder()- Cancel an order (refunds buyer)disputeOrder()- Dispute an order
getOrder(uint256 orderId)- Get order detailsgetBuyerOrders(address buyer)- Get all orders for a buyergetSellerOrders(address seller)- Get all orders for a sellergetOrders(uint256[] orderIds)- Get multiple orders
setPlatformFee(uint256 newFee)- Update platform fee (owner only)setMinOrderValue(uint256 newValue)- Update minimum order value (owner only)transferOwnership(address newOwner)- Transfer contract ownership
- Access Control: Only authorized parties can update orders
- Status Validation: Prevents invalid status transitions
- Payment Escrow: Funds held securely until delivery
- Automatic Refunds: Cancelled orders automatically refund
- Reentrancy Protection: Built-in protection against reentrancy attacks
- Input Validation: All inputs are validated before processing
- Platform Fee: Configurable (default: 1% = 100 basis points)
- Minimum Order Value: Configurable (default: 0.001 ETH)
- Fee Collection: Collected at order creation
- Refund Policy: Platform fee is non-refundable
The contract emits the following events for off-chain tracking:
OrderCreated- When a new order is createdOrderStatusUpdated- When order status changesTrackingNumberAdded- When tracking number is addedOrderDisputed- When an order is disputedOrderCancelled- When an order is cancelled
npm testAfter deployment, update the contract addresses in:
lib/contract.ts- Frontend contract configuration
Contracts are automatically verified on Etherscan after deployment. Manual verification:
npx hardhat verify --network sepolia <CONTRACT_ADDRESS> <CONSTRUCTOR_ARGS>- Import the contract ABI from
lib/abis/OrderTracking.ts - Use the contract address from
lib/contract.ts - Use wagmi hooks to interact with the contract
Example:
import { useWriteContract, useReadContract } from "wagmi";
import { OrderTrackingABI } from "@/lib/abis/OrderTracking";
import { getContractAddress } from "@/lib/contract";
// Read order
const { data: order } = useReadContract({
address: getContractAddress(chainId),
abi: OrderTrackingABI,
functionName: "getOrder",
args: [orderId],
});
// Create order
const { writeContract } = useWriteContract();
writeContract({
address: getContractAddress(chainId),
abi: OrderTrackingABI,
functionName: "createOrder",
args: [
seller,
productName,
description,
quantity,
currency,
delivery,
network,
metadata,
],
value: parseEther(price),
});- Never commit private keys to version control
- Test thoroughly on testnets before mainnet deployment
- Verify contracts on block explorers for transparency
- Monitor gas costs - optimize if needed
- Keep contract owner key secure - use multisig for production
MIT License - See LICENSE file for details