Push notification backend server for Bitcoin Silver wallet.
- Bitcoin Silver node running with ZMQ enabled
- PostgreSQL database
- Redis (optional, for future enhancements)
- Node.js v18 or higher
- Firebase project with Admin SDK service account
# On your local machine, from the wallet directory:
scp -r backend btcwallet@YOUR_VPS_IP:~/btcs-notification-backend
# Or use rsync:
rsync -avz backend/ btcwallet@YOUR_VPS_IP:~/btcs-notification-backend/ssh btcwallet@YOUR_VPS_IP
cd ~/btcs-notification-backend
npm install# Create database and user
sudo -u postgres psql << EOF
CREATE DATABASE btcs_notifications;
CREATE USER btcs_backend WITH PASSWORD 'YOUR_SECURE_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE btcs_notifications TO btcs_backend;
\q
EOF
# Create tables
PGPASSWORD='YOUR_SECURE_PASSWORD' psql -U btcs_backend -d btcs_notifications -h localhost << 'EOF'
CREATE TABLE device_tokens (
id SERIAL PRIMARY KEY,
address VARCHAR(100) NOT NULL,
device_token TEXT NOT NULL,
platform VARCHAR(10) DEFAULT 'android',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_active TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(address, device_token)
);
CREATE INDEX idx_address ON device_tokens(address);
CREATE TABLE notifications (
id SERIAL PRIMARY KEY,
address VARCHAR(100) NOT NULL,
txid VARCHAR(64) NOT NULL,
amount DECIMAL(16,8) NOT NULL,
sent BOOLEAN DEFAULT FALSE,
confirmed BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(address, txid)
);
\q
EOF- Go to Firebase Console
- Select your project (or create one)
- Go to Project Settings → Service Accounts
- Click Generate new private key
- Save the downloaded JSON file as
firebase-admin-key.jsonin the project root
# Upload the key file to VPS
scp firebase-admin-key.json btcwallet@YOUR_VPS_IP:~/btcs-notification-backend/cd ~/btcs-notification-backend
cp .env.example .env
nano .envUpdate these values in .env:
DB_PASSWORD- Your PostgreSQL passwordAPI_KEY- A secure random string for API authenticationLIVECOINWATCH_API_KEY- Your LiveCoinWatch API key (for price monitoring)
# Test run
npm start
# In another terminal, test the health endpoint
curl http://localhost:3000/healthnpm install -g pm2
# Start the backend
pm2 start src/server.js --name btcs-backend
# Save PM2 configuration
pm2 save
# Setup auto-start on boot
pm2 startup
# Monitor
pm2 status
pm2 logs btcs-backend
pm2 monitCreate /etc/systemd/system/btcs-backend.service:
[Unit]
Description=Bitcoin Silver Notification Backend
After=network.target postgresql.service
[Service]
Type=simple
User=btcwallet
WorkingDirectory=/home/btcwallet/btcs-notification-backend
ExecStart=/usr/bin/node src/server.js
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.targetEnable and start:
sudo systemctl daemon-reload
sudo systemctl enable btcs-backend
sudo systemctl start btcs-backend
sudo systemctl status btcs-backend
# View logs
journalctl -u btcs-backend -fGET /healthPOST /api/register
Content-Type: application/json
{
"address": "btcs1q...",
"device_token": "fcm_token...",
"platform": "android"
}POST /api/unregister
Content-Type: application/json
{
"address": "btcs1q...",
"device_token": "fcm_token..."
}GET /api/notifications/:address?limit=50GET /api/statsPOST /api/test-notification
Content-Type: application/json
{
"device_token": "fcm_token..."
}sudo ufw allow 22/tcp # SSH
sudo ufw allow 3000/tcp # API (or use nginx reverse proxy)
sudo ufw enable# PM2
pm2 logs btcs-backend
# systemd
journalctl -u btcs-backend -f
# Log files
tail -f combined.log
tail -f error.logpsql -U btcs_backend -d btcs_notifications -h localhost
# Inside psql:
SELECT * FROM device_tokens;
SELECT * FROM notifications ORDER BY created_at DESC LIMIT 10;bitcoinsilver-cli getblockchaininfo- Check Bitcoin node is running:
bitcoinsilver-cli getblockchaininfo - Check database credentials in
.env - Check logs:
pm2 logs btcs-backendorjournalctl -u btcs-backend
- Check
firebase-admin-key.jsonexists in project root - Verify Firebase project has Cloud Messaging enabled
- Check device is registered: Query database
- Check ZMQ is working: Look for "Processing transaction" in logs
- Check PostgreSQL is running:
sudo systemctl status postgresql - Check database exists:
sudo -u postgres psql -l | grep btcs - Check credentials in
.env
- Never commit
.envorfirebase-admin-key.jsonfiles - Use strong database passwords
- Keep Firebase service account key secret
- Run behind nginx with SSL in production
- Use firewall to restrict access
- Regular security updates:
sudo apt update && sudo apt upgrade
# On local machine, update code then:
rsync -avz backend/ btcwallet@YOUR_VPS_IP:~/btcs-notification-backend/
# On VPS:
cd ~/btcs-notification-backend
npm install
pm2 restart btcs-backend