Decentralized RAG with x402 Micropayments on Cronos EVM
A hackathon MVP demonstrating how AI agents can automatically pay knowledge authors via micropayments when their content is cited in AI responses.
Problem: AI models use human-created content but authors receive nothing.
Solution: CogniShare Protocol tracks who contributed what knowledge and automatically sends them CRO micropayments when AI cites their work.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CogniShare Protocol โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ 1. Author uploads PDF + Wallet Address โ
โ โ โ
โ 2. Document โ Chunks โ Embeddings โ Pinecone โ
โ (Each chunk tagged with author's wallet!) โ
โ โ โ
โ 3. User asks AI a question โ
โ โ โ
โ 4. RAG retrieves relevant chunks โ
โ โ โ
โ 5. x402 Payment: Send CRO to chunk authors โ
โ โ โ
โ 6. GPT-4o-mini generates answer using context โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Create virtual environment
python -m venv venv
# Activate (Windows)
.\venv\Scripts\activate
# Activate (Mac/Linux)
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt# Copy template
copy env.template .env # Windows
cp env.template .env # Mac/Linux
# Edit .env with your API keysMinimum Required:
OPENAI_API_KEY- For embeddings and chat
Optional (for full features):
PINECONE_API_KEY- Production vector storageCRONOS_PRIVATE_KEY- Real blockchain payments
streamlit run app.pyOpen http://localhost:8501 in your browser!
For on-chain citation tracking:
# Install contract dependencies
pip install py-solc-x
# Deploy to Cronos Testnet
python deploy_contract.pySee SMART_CONTRACT_SETUP.md for detailed instructions.
If API keys are missing, the app automatically uses:
- Mock Vector Storage - In-memory storage with demo data
- Mock Payments - Simulated TX hashes (no real CRO sent)
This lets you test the full UX without any configuration!
With all API keys configured:
- Pinecone - Scalable vector database
- Real Payments - Actual CRO transactions on Cronos Testnet
CogniShare-Protocol/
โโโ app.py # Streamlit UI (main entry point)
โโโ rag_core.py # RAG Engine (embeddings, search)
โโโ payment_manager.py # Cronos x402 payments + Smart Contract
โโโ deploy_contract.py # Smart contract deployment script
โโโ requirements.txt # Python dependencies
โโโ env.template # Environment variables template
โโโ contracts/
โ โโโ CogniShareRegistry.sol # Smart contract for on-chain citations
โ โโโ README.md # Contract documentation
โโโ contract_data.json # Deployed contract address & ABI (auto-generated)
โโโ SMART_CONTRACT_SETUP.md # Smart contract deployment guide
โโโ README.md # You are here!
engine = RAGEngine()
# Ingest a document with author attribution
engine.ingest_document(pdf_file, "0xAuthorWallet...")
# Query for relevant chunks
results = engine.query("What is decentralized AI?")
# Returns: [{"text": "...", "author_wallet": "0x...", "score": 0.95}, ...]Key Feature: Every chunk stores author_wallet in Pinecone metadata!
payment = CronosPayment(use_testnet=True)
# Pay authors from RAG results
result = payment.pay_authors(
author_wallets=["0x123...", "0x456..."],
amount_per_citation=0.01 # CRO per citation
)
# Returns: {"tx_hashes": [...], "total_paid": 0.02, ...}Key Feature: Deduplicates wallets and batches payments!
- Sidebar: Upload documents, configure API keys
- Main: Chat interface with real-time payment visualization
- State: Uses
st.session_statefor chat history
| Setting | Value |
|---|---|
| Network Name | Cronos Testnet |
| RPC URL | https://evm-t3.cronos.org |
| Chain ID | 338 |
| Symbol | tCRO |
| Explorer | https://explorer.cronos.org/testnet3 |
- Visit Cronos Faucet
- Enter your wallet address
- Receive free test CRO
- Never commit
.env- Contains private keys! - Use testnet first - Validate before mainnet
- Rotate keys regularly - Best practice
โ
PDF ingestion with author wallet attribution
โ
Semantic search with Pinecone/mock fallback
โ
x402 micropayments on Cronos EVM
โ
Smart Contract Registry - On-chain citation tracking
โ
Event Logs - Immutable audit trail for every citation
โ
GPT-4o-mini for answer generation
โ
Beautiful Streamlit UI
โ
Graceful degradation (mock modes)
โ
Transaction tracking & explorer links
โ
Batch payments - Gas-optimized multi-author payments
MIT License - Build on this!
Built for the Cronos Hackathon ๐
Decentralizing AI, one citation at a time.