ScanChain is a blockchain-based product authenticity verification system built on BNB Greenfield for decentralized storage and BNB Smart Chain for immutable hash storage. The system allows manufacturers to upload product documents and generate QR codes for consumer verification.
- File Storage: Secure file storage on BNB Greenfield Testnet
- Blockchain Verification: Immutable hash storage on BSC Testnet
- QR Code Generation: Dynamic QR codes for easy product verification
- REST API: Clean API endpoints for upload and verification
- Hash Verification: SHA-256 hash comparison for tamper detection
- Multi-format Support: PDF and JSON file support
See ScanChain in action - from product upload to QR code verification!
- Backend: Python with Flask
- Blockchain: BNB Smart Chain (BSC) Testnet
- Storage: BNB Greenfield Testnet
- Hashing: SHA-256 via hashlib
- QR Codes: qrcode library
- Smart Contract: Solidity
Before running this project, ensure you have:
- Python (v3.8 or later)
- pip
- BSC Testnet account with test BNB
- BNB Greenfield Testnet account
- Git
git clone https://github.com/HashimCodeDev/ScanChain.git
cd ScanChain
uv syncCopy the environment file and configure:
cp .env.example .envUpdate .env with your credentials:
# BNB Greenfield Configuration
GREENFIELD_ADDRESS=your_testnet_address
GREENFIELD_PRIVATE_KEY=your_testnet_private_key
# BNB Smart Chain Configuration
CONTRACT_ADDRESS=0x...
BSC_RPC_URL=https://data-seed-prebsc-1-s1.binance.org:8545
BSC_PRIVATE_KEY=your_bsc_private_key
# Server Configuration
PORT=3000
NODE_ENV=development
# Greenfield Testnet Configuration
GREENFIELD_RPC_URL=https://gnfd-testnet-fullnode-tendermint-us.bnbchain.org:443
GREENFIELD_CHAIN_ID=5600Deploy the contract using Remix IDE:
- Contract code:
contracts/ProductAuthenticity.sol - Network: BSC Testnet (Chain ID: 97)
- Update
CONTRACT_ADDRESSin.envafter deployment
uv run python test_app.pyuv run python app.py
# or
uv run python run.pyThe server will start on http://localhost:5000
GET /api/healthPOST /api/upload
Content-Type: multipart/form-data
Body:
- productId: string (required)
- file: file (PDF or JSON, max 10MB)Response:
{
"success": true,
"productId": "ABC123456789",
"fileHash": "sha256_hash_here",
"greenfieldUrl": "https://gnfd-testnet-sp1.bnbchain.org/bucket/file",
"txHash": "0x...",
"qrCode": "data:image/png;base64,..."
}POST /api/verify
Content-Type: application/json
{
"productId": "ABC123456789",
"greenfieldUrl": "https://gnfd-testnet-sp1.bnbchain.org/bucket/file"
}Response:
{
"success": true,
"isVerified": true,
"productId": "ABC123456789",
"storedHash": "original_hash",
"currentHash": "current_hash",
"message": "Product is authentic"
}GET /api/product/:productIdPOST /api/qr/generate
{
"productId": "ABC123456789",
"contractAddress": "0x...",
"metadata": {
"manufacturer": "Company Name",
"productName": "Product Name"
}
}POST /api/qr/parse
{
"qrData": "qr_code_json_string"
}POST /api/qr/scan
{
"qrData": "qr_code_json_string"
}ScanChain/
βββ contracts/
β βββ ProductAuthenticity.sol # Smart contract
βββ services/
β βββ greenfield_service.py # BNB Greenfield integration
β βββ blockchain_service.py # BSC integration
β βββ qr_service.py # QR code utilities
β βββ auth_service.py # Authentication service
β βββ database_service.py # Database operations
βββ routes/
β βββ auth_routes.py # Authentication routes
βββ public/
β βββ *.html # Frontend files
βββ data/
β βββ *.json # Data storage files
βββ app.py # Main Flask application
βββ run.py # Server runner
βββ test_app.py # Test suite
βββ pyproject.toml # Python dependencies (uv)
βββ .env
βββ README.md
The ProductAuthenticity.sol contract provides:
storeProductHash(string productId, string fileHash)- Store product hashgetProductHash(string productId)- Retrieve product hashgetProductInfo(string productId)- Get full product informationproductExists(string productId)- Check if product exists
- RPC URL: https://data-seed-prebsc-1-s1.binance.org:8545
- Chain ID: 97
- Symbol: tBNB
- Explorer: https://testnet.bscscan.com/
- Faucet: https://testnet.binance.org/faucet-smart
- RPC URL: https://gnfd-testnet-fullnode-tendermint-us.bnbchain.org:443
- Chain ID: 5600
- Explorer: https://testnet.greenfieldscan.com/
Run the test suite to verify functionality:
uv run python test_app.pyThis will test:
- Environment variables
- Python dependencies
- Hash generation
- JSON processing
- Service availability
- Input Validation: All inputs are validated and sanitized
- File Type Restrictions: Only PDF and JSON files allowed
- Size Limits: 10MB maximum file size
- Error Handling: Comprehensive error handling and logging
- Environment Variables: Sensitive data stored in environment variables
The API returns consistent error responses:
{
"success": false,
"error": "Error message description"
}Common error codes:
400: Bad Request (validation errors)404: Not Found (product not found)500: Internal Server Error503: Service Unavailable (blockchain/storage issues)
- Create new service files in
services/ - Add routes in
routes/ - Update validation in Flask app
- Add tests in
test_app.py
Required variables:
GREENFIELD_ADDRESS- Your Greenfield addressGREENFIELD_PRIVATE_KEY- Greenfield private keyCONTRACT_ADDRESS- Deployed contract addressBSC_PRIVATE_KEY- BSC account private key
Optional variables:
PORT- Server port (default: 3000)NODE_ENV- Environment mode
- Contract not deployed: Deploy using Remix IDE with the provided Solidity contract
- Network issues: Check RPC URLs and internet connection
- Private key errors: Ensure keys are valid and have test funds
- File upload fails: Check file size and type restrictions
The application includes fallbacks for development:
- Mock Greenfield URLs when service unavailable
- Mock blockchain transactions when contract not deployed
- Detailed error messages in development mode
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License.
For support and questions:
- Check the troubleshooting section
- Run
uv run python test_app.pyto verify setup - Review server logs for error details
Future enhancements:
- Frontend web application
- Mobile app for QR scanning
- Batch upload functionality
- Advanced analytics dashboard
- Multi-chain support
- IPFS integration as backup storage
Built with β€οΈ for the BNB Chain ecosystem