A web application that classifies Bitcoin addresses for illegal activity detection using machine learning.
- Python 3.8+
- Node.js 16+
- PostgreSQL
-
Clone and setup the project:
chmod +x setup.sh ./setup.sh
-
Set up the database:
createdb bitcoin_classifier psql -d bitcoin_classifier -f database/schema.sql
-
Configure environment:
cd backend cp env.example .env # Edit .env with your database credentials
-
Start the application:
# Terminal 1: Start backend cd backend source venv/bin/activate python run.py # Terminal 2: Start frontend cd frontend npm run dev
-
Open your browser:
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
The system now supports exact research-based feature calculations using the original research code from moduleG.py. This ensures feature values match your research exactly.
-
Research Mode (Recommended): Uses graph-tool and exact research functions
- Requires graph-tool installation
- Uses the original Bitcoin graph and reverse map
- Calculates features exactly as in your research
-
API Mode (Fallback): Uses BlockCypher API
- No additional dependencies
- Approximates features using transaction data
- Works when research files are not available
# Install graph-tool for exact calculations
cd backend
./install_graph_tool.sh
# Or manually install graph-tool:
conda install -c conda-forge graph-toolFor exact calculations, place these files in backend/scripts/:
BitcoinGraph.gt- The Bitcoin transaction graphrevmap.pkl- Address to vertex mapping
The system will automatically detect these files and use research mode when available.
BlockChainAnalysis/
├── backend/ # Flask API server
│ ├── app/
│ │ ├── routes/ # API endpoints
│ │ ├── services/ # Business logic
│ │ │ ├── feature_service.py # Feature extraction (research + API)
│ │ │ └── ml_service.py # ML predictions
│ │ └── models/ # Database models
│ ├── scripts/ # Research code
│ │ ├── moduleG.py # Original research functions
│ │ ├── BitcoinGraph.gt # Bitcoin transaction graph
│ │ └── revmap.pkl # Address mapping
│ ├── requirements.txt # Python dependencies
│ └── run.py # Application entry point
├── frontend/ # Svelte web application
│ ├── src/
│ │ ├── components/ # Svelte components
│ │ └── services/ # API client
│ ├── package.json
│ └── vite.config.js
├── database/ # Database schema
│ └── schema.sql
├── ml-models/ # Trained ML models
├── FeatureExtraction/ # Original feature extraction code
├── NonStructuralTraining/ # Original ML training code
└── setup.sh # Setup script
- Backend: Flask (Python)
- Frontend: Svelte + Vite
- Database: PostgreSQL
- ML: TensorFlow (with fallback classification)
- Research: graph-tool + moduleG.py (exact calculations)
- API: BlockCypher for Bitcoin data (fallback)
- Address Classification: Analyze Bitcoin addresses for suspicious activity
- Research-Based Features: Extract 8 key features using exact research calculations
- Dual Mode: Research mode (exact) + API mode (approximate)
- Caching: Store results to avoid re-processing
- History: View classification history
- Real-time Analysis: Live blockchain data via BlockCypher API
POST /api/classify- Classify a Bitcoin addressGET /api/history- Get classification historyGET /api/health- Health check
The application currently uses a fallback classification system. To integrate your trained model:
-
Export your model:
# In your Jupyter notebook model.save('ml-models/bitcoin_classifier.keras') # Save the scaler's data as a JSON file import json scaler_data = { 'mean': scaler.mean_.tolist(), 'scale': scaler.scale_.tolist() } with open('ml-models/scaler.json', 'w') as f: json.dump(scaler_data, f)
-
Update the ML service:
# In backend/app/services/ml_service.py ml_service = MLService( model_path='ml-models/bitcoin_classifier.keras', scaler_path='ml-models/scaler.json' )
# Backend
cd backend
source venv/bin/activate
python run.py
# Frontend
cd frontend
npm run dev# Build frontend
cd frontend
npm run build
# Run backend with gunicorn
cd backend
gunicorn -w 4 -b 0.0.0.0:5000 run:appCreate a .env file in the backend directory:
SECRET_KEY=your-secret-key-here
DATABASE_URL=postgresql://username:password@localhost/bitcoin_classifier
BLOCKCYPHER_API_TOKEN=your-blockcypher-token-here
MODEL_PATH=../ml-models/bitcoin_classifier.keras
SCALER_PATH=../ml-models/scaler.json- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is for educational purposes. Please ensure compliance with applicable laws and regulations when using this tool.