5.4 KiB
5.4 KiB
Tiered Architecture Setup Guide
Complete setup and integration guide for SolaceScanScout tiered architecture.
Quick Start
# 1. Run the setup script
cd explorer-monorepo
bash scripts/setup-tiered-architecture.sh
# 2. Set required environment variables
export JWT_SECRET="your-strong-random-secret-here"
export RPC_URL="http://192.168.11.250:8545"
export DB_HOST="localhost"
export DB_USER="explorer"
export DB_PASSWORD="changeme"
export DB_NAME="explorer"
# 3. Start the API server
cd backend
./bin/api-server
Environment Variables
Required
DB_HOST- PostgreSQL host (default: localhost)DB_USER- Database user (default: explorer)DB_PASSWORD- Database password (default: changeme)DB_NAME- Database name (default: explorer)
Recommended (Production)
JWT_SECRET- Strong random secret for JWT signing (required for production)RPC_URL- RPC endpoint for Track 1 gateway (default: http://localhost:8545)CHAIN_ID- Chain ID (default: 138)PORT- API server port (default: 8080)
Database Migration
Run the Track 2-4 schema migration:
bash scripts/run-migration-0010.sh
This creates:
- Track 2 tables:
addresses,token_transfers,token_balances,internal_transactions - Track 3 tables:
analytics_flows,analytics_bridge_history,token_distribution(materialized view) - Track 4 tables:
operator_events,operator_ip_whitelist,operator_roles - Auth table:
wallet_nonces
User Management
Approve a User for Track 2-4
# Approve user for Track 2
bash scripts/approve-user.sh 0x1234...5678 2
# Approve user for Track 3
bash scripts/approve-user.sh 0x1234...5678 3
# Approve user for Track 4 (operator)
bash scripts/approve-user.sh 0x1234...5678 4 0xAdminAddress
Add IP to Operator Whitelist (Track 4)
bash scripts/add-operator-ip.sh 0x1234...5678 192.168.1.100 "Office network"
API Endpoints
Track 1 (Public - No Auth)
GET /api/v1/track1/blocks/latest- Latest blocksGET /api/v1/track1/txs/latest- Latest transactionsGET /api/v1/track1/block/:number- Block by numberGET /api/v1/track1/tx/:hash- Transaction by hashGET /api/v1/track1/address/:addr/balance- Address balanceGET /api/v1/track1/bridge/status- Bridge status
Track 2 (Authenticated - Track 2+)
GET /api/v1/track2/address/:addr/txs- Address transaction historyGET /api/v1/track2/address/:addr/tokens- Address token balancesGET /api/v1/track2/token/:contract- Token informationGET /api/v1/track2/search?q=- Enhanced searchGET /api/v1/track2/address/:addr/internal-txs- Internal transactions
Track 3 (Authenticated - Track 3+)
GET /api/v1/track3/analytics/flows- Flow trackingGET /api/v1/track3/analytics/bridge- Bridge analyticsGET /api/v1/track3/analytics/token-distribution/:contract- Token distributionGET /api/v1/track3/analytics/address-risk/:addr- Address risk analysis
Track 4 (Authenticated - Track 4 + IP Whitelist)
GET /api/v1/track4/operator/bridge/events- Bridge operator eventsGET /api/v1/track4/operator/validators- Validator statusGET /api/v1/track4/operator/contracts- Contract registryGET /api/v1/track4/operator/protocol-state- Protocol state
Authentication
POST /api/v1/auth/nonce- Request nonce for wallet authPOST /api/v1/auth/wallet- Authenticate with wallet signature
Feature Flags
GET /api/v1/features- Get available features for current user
Frontend Integration
The frontend automatically:
- Loads feature flags on page load
- Shows/hides UI elements based on track level
- Provides wallet connect button for authentication
- Stores auth token in localStorage
Testing Authentication
- Open browser console
- Connect wallet using the "Connect Wallet" button
- Sign the authentication message
- Check
localStorage.getItem('authToken')to verify token storage - Check feature flags:
fetch('/api/v1/features').then(r => r.json())
Indexer Setup
To populate Track 2 data, start the indexers:
cd backend/indexer
go run main.go
The indexers will:
- Index blocks and transactions
- Extract ERC-20 token transfers
- Update address statistics
- Build analytics data
Production Considerations
- JWT Secret: Must be set to a strong random value
- Redis: Replace in-memory cache/rate limiter with Redis
- HTTPS: Use HTTPS in production
- Rate Limiting: Configure appropriate rate limits per track
- IP Whitelist: Strictly enforce for Track 4 operators
- Audit Logging: Monitor
operator_eventstable
Troubleshooting
Migration Fails
- Check database connection:
psql -h $DB_HOST -U $DB_USER -d $DB_NAME -c "SELECT 1" - Verify user has CREATE TABLE permissions
Authentication Fails
- Check JWT_SECRET is set
- Verify wallet_nonces table exists
- Check database connection in auth handlers
Track Routes Not Working
- Verify user is approved: Check
operator_rolestable - Check track level in JWT token
- Verify middleware is applied correctly
Frontend Feature Gating Not Working
- Check browser console for errors
- Verify
/api/v1/featuresendpoint returns correct track - Check localStorage for authToken
Next Steps
- ✅ Run database migration
- ✅ Set environment variables
- ✅ Start API server
- ✅ Approve test users
- ✅ Start indexers
- ✅ Test authentication flow
- ✅ Verify feature gating
For detailed API documentation, see: docs/api/track-api-contracts.md