A decentralized supply chain tracking application built on the Internet Computer Protocol (ICP) using Next.js and Rust. This application allows users to register products, track their supply chain journey, and view analytics through a secure, blockchain-based system.
- Product Registration: Register products with detailed information on the blockchain
- Supply Chain Tracking: Track products through their entire supply chain journey
- Real-time Analytics: View comprehensive analytics and insights
- Internet Identity Authentication: Secure authentication using ICP's Internet Identity
- Decentralized Storage: All data stored securely on the Internet Computer
- QR Code Generation: Generate QR codes for easy product tracking
- Dashboard Management: Manage all your registered products in one place
- Node.js (v18 or higher)
- Rust and Cargo
- DFX (Internet Computer SDK)
- Git
-
Clone the repository: ```bash git clone cd icp-supply-chain ```
-
Install dependencies: ```bash npm install ```
-
Set up Internet Identity and Backend (IMPORTANT - This fixes connection issues): ```bash chmod +x fix_internet_identity_connection.sh ./fix_internet_identity_connection.sh ```
-
Start the Next.js application: ```bash npm run dev ```
-
Access the application:
- Frontend: http://localhost:3000
- Internet Identity: http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943
The fix_internet_identity_connection.sh
script handles:
- Setting up the ICP backend canister
- Deploying Internet Identity locally
- Configuring environment variables
- Testing canister connections
If the automated script doesn't work, you can set up manually:
-
Start DFX: ```bash cd icp_backend dfx start --background --clean ```
-
Deploy the backend: ```bash dfx deploy supply_chain_backend ```
-
Set up Internet Identity: ```bash dfx deps pull dfx deps init internet_identity --argument '(null)' dfx deps deploy ```
-
Update environment variables: ```bash
SUPPLY_CHAIN_ID=$(dfx canister id supply_chain_backend) II_CANISTER_ID=$(dfx canister id internet_identity)
echo "NEXT_PUBLIC_DFX_NETWORK=local" > .env.local echo "NEXT_PUBLIC_SUPPLY_CHAIN_CANISTER_ID=$SUPPLY_CHAIN_ID" >> .env.local echo "NEXT_PUBLIC_INTERNET_IDENTITY_CANISTER_ID=$II_CANISTER_ID" >> .env.local ```
- Visit http://localhost:3000
- Click "Connect Wallet"
- Create or use existing Internet Identity
- Go to "Register Product" page
- Fill in product details:
- Product name and description
- Manufacturer information
- Category and batch number
- Manufacturing date
- Submit to register on blockchain
- Use the "Track Product" page
- Enter product ID or scan QR code
- View complete supply chain history
- Access your dashboard
- View all registered products
- See analytics and insights
- Track product performance
Solution: Run the connection fix script: ```bash chmod +x fix_internet_identity_connection.sh ./fix_internet_identity_connection.sh ```
-
Redeploy backend with latest functions: ```bash chmod +x redeploy_backend.sh ./redeploy_backend.sh ```
-
Test the connection: ```bash chmod +x test_product_management.sh ./test_product_management.sh ```
-
DFX not running: ```bash dfx ping
dfx start --background ```
-
Canister errors: ```bash dfx canister status supply_chain_backend dfx canister status internet_identity ```
-
Clear browser cache:
- Clear cache for localhost:3000
- Try incognito/private browsing
-
Environment variables:
- Check
.env.local
exists - Verify canister IDs are correct
- Check
``` icp-supply-chain/ βββ app/ # Next.js app directory β βββ dashboard/ # Dashboard page β βββ register/ # Product registration β βββ track/ # Product tracking β βββ auth/ # Authentication pages βββ components/ # React components β βββ ui/ # UI components β βββ wallet-connect.tsx # Wallet connection β βββ product-registration-guide.tsx βββ lib/ # Utility libraries β βββ icp-client.ts # ICP blockchain client βββ hooks/ # React hooks β βββ use-icp-wallet.ts # Wallet management βββ icp_backend/ # Rust backend β βββ src/ β β βββ lib.rs # Main backend logic β β βββ types.rs # Data structures β β βββ storage.rs # Data storage β β βββ utils.rs # Utility functions β βββ dfx.json # DFX configuration β βββ supply_chain_backend.did # Candid interface βββ scripts/ # Setup and utility scripts βββ fix_internet_identity_connection.sh βββ redeploy_backend.sh βββ test_product_management.sh ```
- Internet Identity: Secure, passwordless authentication
- Blockchain Storage: Immutable product records
- Cryptographic Signatures: Verified product authenticity
- Decentralized: No single point of failure
```bash
dfx canister call supply_chain_backend register_product '( record { name = "Test Product"; description = "A test product for demonstration"; manufacturer = "Test Manufacturer"; manufacturing_date = "2024-01-15"; category = "Electronics"; batch_number = "BATCH001"; } )' ```
```bash
dfx canister call supply_chain_backend get_all_products
dfx canister call supply_chain_backend get_user_products ```
- Use the setup scripts provided
- Access via localhost:3000
-
Deploy to IC mainnet: ```bash dfx deploy --network ic ```
-
Update environment variables for production
-
Configure custom domain (optional)
register_product(ProductInput)
- Register a new productget_product(ProductId)
- Get product detailsget_user_products()
- Get current user's productsget_all_products()
- Get all products (admin)add_supply_chain_event(ProductId, SupplyChainEvent)
- Add tracking eventget_supply_chain_history(ProductId)
- Get product history
useICPWallet()
- Wallet connection and managementuseToast()
- Toast notifications
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
If you encounter issues:
- Check the troubleshooting section above
- Run the fix scripts: ```bash chmod +x fix_internet_identity_connection.sh ./fix_internet_identity_connection.sh ```
- Check DFX status:
dfx ping
- Clear browser cache
- Restart the development server
Happy tracking! ππ¦