CropRAG is a Verifiable Trait Registry for crops built on the BNB Smart Chain Testnet. It combines Retrieval-Augmented Generation (RAG) with blockchain technology to create an immutable, queryable database of agricultural trait data.
β¨ Key Capabilities:
- πΎ Trait Registration - Register crop traits on the blockchain with full immutability
- π RAG Query System - Query crop traits using natural language with document retrieval
- π Vector Database - In-memory vector DB with cosine similarity for semantic search
- βοΈ Blockchain Integration - Traits stored on BNB Testnet via smart contracts
- π Wallet Management - Automatic wallet integration using backend private key
- π± Modern UI - Premium dark theme with smooth animations and responsive design
Frontend:
- React 18 + Tailwind CSS
- ethers.js v5 for blockchain interaction
- Axios for HTTP requests
- Context API for state management
Backend:
- Node.js + Express
- ethers.js for blockchain transactions
- In-memory vector database with cosine similarity
Blockchain:
- BNB Smart Chain Testnet (Chain ID: 97)
- TraitRegistry Smart Contract
- RPC: https://data-seed-prebsc-1-s1.bnbchain.org:8545
- Node.js (v19+)
- npm or yarn
- BNB Testnet tokens (optional, for gas)
# Clone repository
git clone https://github.com/sambitsargam/CropRAG.git
cd CropRAG
# Backend setup
cd backend
npm install
cp .env.example .env
# Edit .env with your PRIVATE_KEY and CONTRACT_ADDRESS
node index.js
# Frontend setup (new terminal)
cd frontend
npm install
npm startBackend (.env):
PRIVATE_KEY=your_private_key_here
CONTRACT_ADDRESS=0x635BaC4ed3321ba4E8E5f5B1921C73B8ff6f7278
BSC_TESTNET_RPC=https://data-seed-prebsc-1-s1.bnbchain.org:8545
PORT=5001
- Frontend: http://localhost:3000
- Backend: http://localhost:5001
Navigate to Query Traits tab and search for crop information:
Example queries:
- "Tell me about maize drought resistance"
- "What traits improve wheat yield?"
- "Properties of rice early maturity"
Go to Create Trait Asset tab and fill in:
- Crop Name: e.g., "Maize", "Wheat", "Rice"
- Traits: e.g., "drought_resistance, early_maturity, high_yield"
- Data: Trait measurements in JSON or CSV format
Example:
{
"crop": "Maize",
"traits": ["drought_resistance", "early_maturity"],
"yield_kg_per_hectare": 8500,
"water_requirement_mm": 450,
"days_to_maturity": 120,
"protein_content_percent": 10.5
}| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health check |
/api/wallet-info |
GET | Get wallet address from private key |
/api/ingest |
POST | Ingest documents into vector DB |
/api/query |
POST | Query using RAG |
/api/register-trait |
POST | Register trait on blockchain |
/api/trait/:hash |
GET | Retrieve trait record |
/api/records/count |
GET | Get total registered traits |
Query Traits:
curl -X POST http://localhost:5001/api/query \
-H "Content-Type: application/json" \
-d '{"query": "drought resistant crops", "topK": 3}'Register Trait:
curl -X POST http://localhost:5001/api/register-trait \
-H "Content-Type: application/json" \
-d '{
"cropName": "Maize",
"traits": ["drought_resistance", "yield"],
"traitData": "{...}"
}'CropRAG/
βββ backend/
β βββ index.js # Express server & API endpoints
β βββ utils.js # Utility functions
β βββ .env # Environment variables
β βββ package.json
βββ frontend/
β βββ src/
β β βββ components/
β β β βββ LandingPage.js
β β β βββ TraitQuery.js
β β β βββ CreateAsset.js
β β β βββ WalletConnect.js
β β βββ context/
β β β βββ MetaMaskContext.js
β β βββ App.js
β β βββ index.js
β βββ package.json
βββ contracts/
β βββ abi.json # TraitRegistry ABI
βββ data.json # Sample trait data
βββ README.md
TraitRegistry.sol:
- Located at:
0x635BaC4ed3321ba4E8E5f5B1921C73B8ff6f7278 - Network: BNB Smart Chain Testnet
- Function:
registerTrait(string memory traitData, string memory cropName, string[] memory traits)
View on BscScan: https://testnet.bscscan.com/address/0x635BaC4ed3321ba4E8E5f5B1921C73B8ff6f7278
Sample crop trait data is available in data.json. To ingest this data:
curl -X POST http://localhost:5001/api/ingest \
-H "Content-Type: application/json" \
-d @data.json- π Advanced trait filtering
- π Multi-chain support
- π IPFS integration for data storage
- π Mobile app support
- π Real ML embeddings
# Check if port 5001 is in use
lsof -i :5001
# Kill process on port 5001
kill -9 <PID>- Ensure backend is running on http://localhost:5001
- Check browser console (F12) for CORS errors
- Verify .env variables in backend
- Check that PRIVATE_KEY is set in backend .env
- Verify wallet address has BNB tokens for gas
- Use faucet: https://testnet.binance.org/faucet-smart
Get test BNB tokens for the testnet:
- Faucet: https://testnet.binance.org/faucet-smart
- Address: 0x4C92BF08f4672E974dE4dc01806150a977853BfE
- Chain: BNB Smart Chain Testnet (ChainID: 97)
MIT License - see LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and questions:
- Open an issue on GitHub
- Check existing documentation
Built with β€οΈ for agricultural data integrity