A robust, production-ready blockchain timestamping service built on the MultiversX network. This service provides secure, immutable timestamping capabilities with comprehensive API endpoints, caching, monitoring, and webhook notifications.
- Blockchain Timestamping: Create immutable timestamps on MultiversX blockchain
- Hash Verification: Verify the authenticity and timestamp of data hashes
- Batch Operations: Process multiple timestamps and verifications efficiently
- Data Integrity: SHA256 hashing with blockchain proof of existence
- RESTful API: Comprehensive REST API with OpenAPI documentation
- Authentication: API key-based authentication system
- Rate Limiting: Configurable rate limiting and request throttling
- Caching: Redis-based caching for improved performance
- Monitoring: Health checks, metrics, and performance monitoring
- Webhooks: Asynchronous notifications for timestamp events
- Logging: Structured logging with Winston
- Security: Helmet.js security headers and CORS configuration
- Kubernetes Ready: Health, readiness, and liveness probes
- Graceful Shutdown: Proper cleanup and connection management
- Error Handling: Comprehensive error handling and recovery
- Configuration: Environment-based configuration management
- Documentation: Complete API documentation and examples
- Node.js: Version 18.0.0 or higher
- Redis: Version 6.0 or higher (for caching)
- MultiversX Account: Wallet with EGLD for transaction fees
- API Keys: For service authentication
git clone <repository-url>
cd multiversx-timestamp-servicenpm installcp .env.example .envEdit the .env file with your configuration:
# Server Configuration
PORT=3000
HOST=localhost
NODE_ENV=development
# MultiversX Configuration
MULTIVERSX_NETWORK=devnet
MULTIVERSX_WALLET_MNEMONIC=your_wallet_mnemonic_here
MULTIVERSX_GAS_LIMIT=60000000
MULTIVERSX_GAS_PRICE=1000000000
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0
# API Security
API_KEYS=your-api-key-1,your-api-key-2
JWT_SECRET=your-jwt-secret-here
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX=100
# Logging
LOG_LEVEL=info
LOG_FILE=logs/app.log# Using Docker
docker run -d --name redis -p 6379:6379 redis:alpine
# Or using local installation
redis-server# Development mode
npm run dev
# Production mode
npm start| Variable | Description | Default | Required |
|---|---|---|---|
PORT |
Server port | 3000 |
No |
HOST |
Server host | localhost |
No |
NODE_ENV |
Environment | development |
No |
MULTIVERSX_NETWORK |
MultiversX network | devnet |
Yes |
MULTIVERSX_WALLET_MNEMONIC |
Wallet mnemonic | - | Yes |
REDIS_HOST |
Redis host | localhost |
No |
REDIS_PORT |
Redis port | 6379 |
No |
API_KEYS |
Comma-separated API keys | - | Yes |
RATE_LIMIT_MAX |
Rate limit max requests | 100 |
No |
LOG_LEVEL |
Logging level | info |
No |
- Mainnet:
https://gateway.multiversx.com - Testnet:
https://testnet-gateway.multiversx.com - Devnet:
https://devnet-gateway.multiversx.com
http://localhost:3000/api/v1
All API endpoints (except health checks) require an API key:
curl -H "X-API-Key: your-api-key" http://localhost:3000/api/v1/timestampPOST /api/v1/timestamp
Content-Type: application/json
X-API-Key: your-api-key
{
"data": "Hello, World!",
"webhookUrl": "https://your-app.com/webhook",
"metadata": {
"source": "api",
"version": "1.0"
}
}Response:
{
"success": true,
"data": {
"hash": "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e",
"transactionHash": "abc123...",
"timestamp": "2024-01-15T10:30:00.000Z",
"blockHeight": 12345,
"cost": "0.001 EGLD"
},
"message": "Timestamp created successfully"
}POST /api/v1/verify/hash
Content-Type: application/json
X-API-Key: your-api-key
{
"hash": "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e"
}Response:
{
"success": true,
"data": {
"verified": true,
"timestamp": "2024-01-15T10:30:00.000Z",
"transactionHash": "abc123...",
"blockHeight": 12345,
"age": "2 hours ago"
}
}POST /api/v1/verify/data
Content-Type: application/json
X-API-Key: your-api-key
{
"data": "Hello, World!"
}POST /api/v1/verify/batch
Content-Type: application/json
X-API-Key: your-api-key
{
"hashes": [
"hash1...",
"hash2...",
"hash3..."
]
}GET /api/v1/health # Basic health check
GET /api/v1/health/ready # Kubernetes readiness probe
GET /api/v1/health/live # Kubernetes liveness probe
GET /api/v1/health/metrics # Detailed metrics
GET /api/v1/health/version # Version informationGET /api/v1/timestamp/stats # Timestamp statistics
GET /api/v1/verify/stats # Verification statistics
GET /api/v1/timestamp/history # Timestamp history
GET /api/v1/verify/history # Verification historyThe service supports webhook notifications for asynchronous events:
- Timestamp Created: When a timestamp is successfully created
- Timestamp Failed: When timestamp creation fails
- Verification Completed: When verification is completed
{
"event": "timestamp.created",
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"hash": "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e",
"transactionHash": "abc123...",
"blockHeight": 12345,
"metadata": {
"source": "api"
}
}
}- Webhooks include a signature header for verification
- Automatic retry with exponential backoff
- Webhook endpoint validation
The service includes a complete PM2 deployment setup for production environments:
# Make deployment script executable
chmod +x deploy.sh
# Deploy to production
./deploy.sh production
# Deploy to development
./deploy.sh developmentThe ecosystem.config.js file provides comprehensive PM2 configuration:
module.exports = {
apps: [{
name: 'multiversx-timestamp-service',
script: './src/app.js',
instances: 'max',
exec_mode: 'cluster',
max_memory_restart: '1G',
node_args: '--max-old-space-size=1024'
}]
};-
Install PM2 globally:
npm install -g pm2
-
Start the application:
pm2 start ecosystem.config.js --env production
-
Save PM2 configuration:
pm2 save pm2 startup
-
Monitor the application:
pm2 status pm2 logs pm2 monit
For production deployment, configure Nginx as a reverse proxy:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}Secure your deployment with Let's Encrypt:
# Install Certbot
sudo apt install certbot python3-certbot-nginx
# Obtain SSL certificate
sudo certbot --nginx -d your-domain.com
# Auto-renewal
sudo crontab -e
# Add: 0 12 * * * /usr/bin/certbot renew --quietThe service exposes various metrics:
- System Metrics: CPU, memory, disk usage
- Application Metrics: Request count, response times, error rates
- Business Metrics: Timestamps created, verifications performed
- Blockchain Metrics: Transaction success rate, gas usage
Structured logging with multiple levels:
// Log levels: error, warn, info, debug
logger.info('Timestamp created', {
hash: 'abc123...',
transactionHash: 'def456...',
userId: 'user123'
});- Liveness: Application is running
- Readiness: Application can serve traffic
- Startup: Application has completed initialization
# Interface de monitoring
pm2 monit
# Statut des processus
pm2 status
# Logs en temps réel
pm2 logs multiversx-timestamp
# Logs avec filtre
pm2 logs multiversx-timestamp --lines 100Pour un monitoring avancé avec dashboard web, alertes et métriques détaillées :
# Pendant le déploiement
./deploy.sh
# Le script vous demandera votre lien PM2 monitoring
# Ou configuration séparée
./setup-pm2-monitoring.sh# 1. Obtenez vos clés sur https://app.pm2.io
# 2. Configurez le lien
pm2 link <secret_key> <public_key>
# Exemple avec vos clés
pm2 link <secret_key> <public_key>- 📊 Métriques temps réel : CPU, RAM, réseau
- 📝 Logs centralisés : Recherche et filtrage
- 🚨 Alertes automatiques : Email/SMS/Slack
- 📈 Historique performance : Graphiques détaillés
- 🔄 Gestion à distance : Redémarrage, déploiement
- 👥 Collaboration équipe : Partage d'accès
# Vérifier le statut de connexion
pm2 info
# Déconnecter le monitoring
pm2 unlink
# Dashboard web
# https://app.pm2.io# Unit tests
npm test
# Integration tests
npm run test:integration
# Coverage report
npm run test:coverage# Health check
curl http://localhost:3000/health
# Create timestamp
curl -X POST http://localhost:3000/api/v1/timestamp \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{"data": "Hello, World!"}'
# Verify hash
curl -X POST http://localhost:3000/api/v1/verify/hash \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{"hash": "your-hash-here"}'- API Key Authentication: Secure API access
- Rate Limiting: Prevent abuse and DoS attacks
- Input Validation: Comprehensive input sanitization
- Security Headers: Helmet.js security headers
- CORS Configuration: Configurable cross-origin policies
- Request Size Limits: Prevent large payload attacks
- Environment Variables: Never commit secrets to version control
- API Keys: Use strong, unique API keys
- Network Security: Use HTTPS in production
- Access Control: Implement proper access controls
- Monitoring: Monitor for suspicious activity
- Redis Caching: Cache frequently accessed data
- Connection Pooling: Efficient database connections
- Compression: Gzip compression for responses
- Request Batching: Batch operations for efficiency
- Lazy Loading: Load resources on demand
- Caching Strategy: Implement appropriate caching
- Database Indexing: Index frequently queried fields
- Connection Limits: Configure appropriate connection limits
- Memory Management: Monitor memory usage
- Load Balancing: Use load balancers for high traffic
The project includes several deployment and configuration files:
ecosystem.config.js- PM2 configuration for production deploymentdeploy.sh- Automated deployment script with environment detectionPM2_DEPLOYMENT_GUIDE.md- Complete deployment guide with best practicesAPI_TESTING_GUIDE.md- API testing documentation and examplesDockerfile- Docker configuration (alternative deployment)docker-compose.yml- Docker Compose setup
# Application management
pm2 start ecosystem.config.js --env production
pm2 stop multiversx-timestamp-service
pm2 restart multiversx-timestamp-service
pm2 reload multiversx-timestamp-service
pm2 delete multiversx-timestamp-service
# Monitoring
pm2 status
pm2 logs
pm2 monit
pm2 show multiversx-timestamp-service
# Process management
pm2 save
pm2 startup
pm2 unstartup
pm2 resurrect# Install dependencies
npm install
# Start development server
npm run dev
# Start with PM2 (development)
./deploy.sh development
# Run linting
npm run lint
# Format code
npm run formatsrc/
├── config/ # Configuration files
├── controllers/ # Request handlers
├── middlewares/ # Express middlewares
├── routes/ # API routes
├── services/ # Business logic
├── utils/ # Utility functions
└── app.js # Express application
Deployment files:
├── ecosystem.config.js # PM2 configuration
├── deploy.sh # Deployment script
├── PM2_DEPLOYMENT_GUIDE.md
└── API_TESTING_GUIDE.md
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- API Documentation:
/api/v1/docs - Health Endpoints:
/api/v1/health - Postman Collection:
/api/v1/postman
- Connection Errors: Check Redis and MultiversX connectivity
- Authentication Errors: Verify API key configuration
- Rate Limiting: Check rate limit configuration
- Memory Issues: Monitor memory usage and optimize
- Issues: Create an issue on GitHub
- Documentation: Check the API documentation
- Logs: Check application logs for errors
Built with ❤️ by KMCPG for the MultiversX ecosystem