A simple blockchain-based decentralized application for tracking shipment milestones. This project demonstrates smart contract development, testing, and frontend integration.
Problem Solved: Missing or manipulated delivery records in shipping logistics.
Solution: Immutable milestone tracking on blockchain with role-based access control.
-
Core Functions:
- Create shipments (Admin only)
- Add milestones to shipments (Authorized carriers)
- Track shipment progress (Anyone)
- Complete shipments (Authorized carriers)
- Authorize carriers (Admin only)
-
Blockchain Benefits:
- Immutable milestone records
- Transparent tracking
- No single point of failure
- Verifiable delivery history
- Smart Contract: Solidity ^0.8.19
- Development Framework: Hardhat
- Frontend: HTML, CSS, JavaScript
- Blockchain Interaction: Web3.js
- Testing: Hardhat + Chai
- Local Blockchain: Hardhat Network
shipment-tracker/
├── contracts/
│ └── ShipmentTracker.sol # Main smart contract
├── test/
│ └── ShipmentTracker.test.js # Comprehensive tests
├── scripts/
│ └── deploy.js # Deployment script
├── frontend/
│ ├── index.html # Main UI
│ ├── app.js # Web3 integration
│ ├── style.css # Styling
│ └── contract.json # Contract ABI & address (generated)
├── hardhat.config.js # Hardhat configuration
└── package.json # Dependencies
- Node.js (v16 or higher)
- MetaMask browser extension
- Git
-
Clone and navigate to project:
cd shipment-tracker -
Install dependencies:
npm install
-
Compile the smart contract:
npm run compile
-
Run tests:
npm test
npm run startThis starts a local Hardhat network on http://127.0.0.1:8545
In a new terminal:
npm run deployThis deploys the contract and saves the address/ABI to frontend/contract.json
-
Add Hardhat network to MetaMask:
- Network Name: Hardhat Local
- RPC URL: http://127.0.0.1:8545
- Chain ID: 1337
- Currency Symbol: ETH
-
Import test accounts (use private keys from Hardhat output)
Open frontend/index.html in your browser or use a local server:
# Option 1: Direct file
# Just open frontend/index.html in browser
# Option 2: Local server (recommended)
cd frontend
python -m http.server 8080
# Then visit http://localhost:8080- Admin (Contract Owner): Can create shipments and authorize carriers
- Authorized Carriers: Can add milestones and complete shipments
- Anyone: Can track shipments
-
Admin creates a shipment:
- Go to Admin Panel
- Enter shipment ID, carrier address, customer address
- Click "Create"
-
Carrier adds milestones:
- Go to Carrier Panel
- Enter shipment ID and milestone description
- Set timestamp and click "Add Milestone"
-
Anyone tracks shipment:
- Go to Track Shipment tab
- Enter shipment ID
- View progress and milestones
-
Carrier completes shipment:
- Use "Complete Shipment" in Carrier Panel
createShipment(shipmentId, carrier, customer)- Create new shipmentaddMilestone(shipmentId, description, timestamp)- Add milestonecompleteShipment(shipmentId)- Mark shipment as completedauthorizeCarrier(carrier)- Authorize new carrier
getShipment(shipmentId)- Get shipment detailsgetMilestone(shipmentId, index)- Get specific milestonegetAllShipmentIds()- Get all shipment IDsgetMilestoneCount(shipmentId)- Get milestone count
Run the comprehensive test suite:
npm test- Contract deployment and initialization
- Carrier authorization
- Shipment creation with validation
- Milestone addition with restrictions
- Shipment completion
- Access control enforcement
- Error handling
ShipmentTracker
✓ Should set the right owner
✓ Should authorize owner as carrier by default
✓ Should allow owner to authorize carriers
✓ Should create a new shipment
✓ Should add milestone by authorized carrier
✓ Should complete shipment
... (25+ tests)
- Ensure you're on the correct network (Hardhat Local)
- Refresh the page after network changes
- Check that contract is deployed
- Ensure you have enough ETH for gas
- Check if you have the right permissions
- Verify input parameters
- Make sure you ran
npm run deploy - Check that
frontend/contract.jsonexists - Restart local blockchain if needed
This project demonstrates:
- Smart Contract Development: Solidity basics, modifiers, events
- Testing: Comprehensive test coverage with Hardhat/Chai
- Frontend Integration: Web3.js for blockchain interaction
- Security: Access control, input validation
- Development Workflow: Compile, test, deploy cycle
- Add more complex milestone types
- Implement payment escrow
- Add GPS location tracking
- Create mobile app interface
- Deploy to testnets (Sepolia, Goerli)
- Add more sophisticated UI/UX
# Kill process on port 8545
npx kill-port 8545npm run clean
npm run compile
npm run deploySettings → Advanced → Reset Account (clears transaction history)
MIT License - Feel free to use for educational purposes.
Note: This is a simplified educational DApp. For production use, additional security audits and features would be required.