A privacy-preserving AI-powered chat application with cryptocurrency integration, built using NEAR AI Cloud that runs inside a Trusted Execution Environment (TEE). ZChat enables users to interact with an intelligent assistant that can fetch crypto prices, provide charity information, and facilitate hotel bookings - all while maintaining privacy through TEE.
- Privacy-Preserving AI: Powered by NEAR AI Cloud running inside TEE (Trusted Execution Environment) for secure, private AI computations
- Wallet Integration: Connect your Solana wallet for seamless Web3 interactions
- Cryptocurrency Price Tracking: Real-time crypto prices with interactive charts powered by Plotly
- Charity Donations: Browse and donate to children's cancer research charities
- Hotel Bookings: Search and book hotels with cryptocurrency
- Chat Persistence: MongoDB-backed chat history storage
- Model Context Protocol (MCP): Tool-calling capabilities for extended functionality
- Modern UI: Chat interface with markdown support and real-time updates
User Input
β
ChatInterface (React/Next.js Frontend)
β
POST /api/chat (Next.js API Route)
β
NEAR AI Cloud (DeepSeek V3.1)
β
MCP Client ββ MCP Server (Tools)
β
ββ CoinGecko API (Price Data)
ββ Charities JSON (Mock Data)
ββ Hotels JSON (Mock Data)
ββ MongoDB (Chat Persistence)
- Next.js 16 - React framework with App Router
- React 19 - UI library
- TypeScript - Type safety
- Tailwind CSS - Styling
- Plotly.js - Interactive cryptocurrency charts
- React Markdown - Rich message formatting
- Next.js API Routes - Serverless API endpoints
- NEAR AI Cloud - Privacy-preserving LLM with TEE
- MongoDB - Chat history and wallet storage
- Model Context Protocol (MCP) - Tool integration framework
- get_token_price - Fetch crypto prices from CoinGecko
- get_charity_details - Retrieve charity information
- get_hotel_details - Search and retrieve hotel data
- process_payment - Handle cryptocurrency transactions
- get_price_history - Fetch historical price data for charts
Before setting up the project, ensure you have:
- Node.js (v18 or higher)
- pnpm (recommended package manager)
- MongoDB instance (local or cloud)
- NEAR AI Cloud API key (Get one here)
git clone <repository-url>
cd zchatpnpm installCreate a .env file in the root directory with the following variables:
# NEAR AI Cloud Configuration
NEAR_API_KEY=your_near_ai_cloud_api_key_here
# Site Configuration
SITE_URL=http://localhost:3000
# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/Zchat
# or use MongoDB Atlas:
# MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/Zchat
# Database and Collection Names
DB_NAME=Zchat
COLLECTION_NAME=chatGetting Your NEAR AI Cloud API Key:
- Visit https://cloud.near.ai/
- Sign up or log in to your account
- Navigate to API Keys section
- Generate a new API key
- Copy and paste it into your
.envfile
Option A: Local MongoDB
# Install MongoDB (Ubuntu/Debian)
sudo apt-get install mongodb
# Start MongoDB service
sudo systemctl start mongodbOption B: MongoDB Atlas (Cloud)
- Create a free account at MongoDB Atlas
- Create a new cluster
- Get your connection string
- Add it to your
.envfile asMONGODB_URI
# Start the Next.js development server
pnpm devThe application will be available at http://localhost:3000
The MCP server runs automatically when the API is called. However, you can test it independently:
# Run MCP server standalone
pnpm run mcp-serverOnce the application is running, try these prompts in the chat:
-
Cryptocurrency Prices:
- "What's the current price of Bitcoin?"
- "Show me the price of ZEC in USD"
- "Get me the price history of Ethereum"
-
Charity Donations:
- "Show me charities for children's cancer research"
- "Tell me about charity #1"
- "I want to donate to a cancer research charity"
-
Hotel Bookings:
- "Find hotels in Miami"
- "Show me hotels in Dubai"
- "Tell me about the rooms at hotel #2"
-
Interactive Charts:
- "Show me Bitcoin price history for the last 7 days"
- "Display Ethereum price chart"
zchat/
βββ app/
β βββ api/
β β βββ chat/
β β βββ route.ts # Main chat API endpoint
β βββ components/
β β βββ ChatInterface.tsx # Main chat UI component
β β βββ MarkdownRenderer.tsx # Message rendering with markdown
β β βββ PriceChart.tsx # Plotly chart component
β β βββ ...
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Home page
βββ data/
β βββ charities.json # Charity data (mocked)
β βββ hotels.json # Hotel data (mocked)
βββ lib/
β βββ mongodb.ts # MongoDB connection and utilities
βββ mcp-server/
β βββ index.ts # MCP server implementation
β βββ README.md # MCP server documentation
βββ public/ # Static assets
βββ .env # Environment variables (create this)
βββ package.json # Project dependencies
βββ README.md # This file
ZChat uses NEAR AI Cloud which runs inside a Trusted Execution Environment (TEE). This means:
- All AI computations happen in an isolated, secure environment
- Your conversations are processed privately and securely
- Data is encrypted during processing
- No unauthorized access to your chat data or wallet information
This project includes mocked data for hotels and charities in the data/ directory:
data/hotels.json- Contains mock hotel listings with various room types and pricingdata/charities.json- Contains mock children's cancer research charities
Why Mocked Data?
These charities and hotels don't allow testing with test wallets on testnet environments. To provide a seamless development and testing experience without requiring real transactions, we've created realistic mock data that simulates the actual behavior of these services. This allows you to:
- Test the full user flow without real payments
- Develop and debug features safely
- Demonstrate the application's capabilities without financial risk
For production deployment, these would need to be replaced with real API integrations and proper payment processing systems that support mainnet transactions.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
# Check if MongoDB is running
sudo systemctl status mongodb
# Restart MongoDB
sudo systemctl restart mongodb# Clear cache and reinstall
rm -rf node_modules pnpm-lock.yaml
pnpm install- Verify your API key is correct in
.env - Check if you have an active internet connection
- Ensure your API key has not expired
- Make sure all dependencies are installed
- Check that TypeScript compilation is working:
pnpm run mcp-server - Review MCP server logs for specific errors
- NEAR AI Cloud Documentation
- Model Context Protocol
- Next.js Documentation
- MongoDB Documentation
- CoinGecko API
Built with β€οΈ using NEAR AI Cloud and privacy-preserving technology