A Node.js backend service for the L1Beat, providing API endpoints for Avalanche L1 data and metrics.
- Chain Data: Fetch and store information about Avalanche chains
- Validator Data: Track validators for each chain
- TVL Tracking: Historical and current TVL data for Avalanche
- TPS Metrics: Track transactions per second for each chain and the entire network
- Caching: In-memory caching for improved performance
- Structured Logging: Comprehensive logging system
- Security: Rate limiting, input validation, and security headers
- Node.js and Express: Backend framework
- MongoDB: Database for storing chain, validator, TVL, and TPS data
- Mongoose: MongoDB object modeling
- Winston: Structured logging
- Helmet: Security headers
- Express Validator: Input validation
- Express Rate Limit: API rate limiting
- Node-cron: Scheduled tasks
GET /api/chains: Get all chainsGET /api/chains/:chainId: Get a specific chain by IDGET /api/chains/:chainId/validators: Get validators for a specific chain
GET /api/tvl/history: Get historical TVL dataGET /api/tvl/health: Check TVL data health
GET /api/chains/:chainId/tps/history: Get TPS history for a specific chainGET /api/chains/:chainId/tps/latest: Get latest TPS for a specific chainGET /api/tps/network/latest: Get latest network-wide TPSGET /api/tps/network/history: Get historical network-wide TPSGET /api/tps/health: Check TPS data healthGET /api/tps/diagnostic: Get diagnostic information about TPS dataGET /api/tps/status: Get TPS status summary
- Node.js (v16.20.1 or higher)
- MongoDB
-
Clone the repository:
git clone https://github.com/L1Beat/L1Beat-backend.git cd l1beat-backend -
Install dependencies:
npm install -
Create a
.envfile in the root directory with the following variables:# Development Database DEV_MONGODB_URI=mongodb://localhost:27017/glacier-chains PROD_MONGODB_URI=mongodb+srv://[username]:[password]@your-mongodb-cluster/glacier-chains NODE_ENV=development PORT=5001 ADMIN_API_KEY=your-admin-key UPDATE_API_KEY=your-update-key # Frontend URLs FRONTEND_URL=http://localhost:5173 -
Start the development server:
npm run dev
For production deployment, set NODE_ENV=production and ensure all environment variables are properly configured.
This application is configured for deployment on Vercel. To deploy:
-
Install the Vercel CLI:
npm install -g vercel -
Create a
.env.productionfile with your production environment variables:NODE_ENV=production PROD_MONGODB_URI=your_production_mongodb_uri ADMIN_API_KEY=your_production_admin_key UPDATE_API_KEY=your_production_update_key -
Run the deployment script:
./deploy.sh
Alternatively, you can deploy directly from the Vercel dashboard by connecting your GitHub repository.
The application runs several scheduled tasks:
- TVL updates: Every 30 minutes
- Chain and TPS updates: Every hour
- TPS verification: Every 15 minutes
The application implements in-memory caching for frequently accessed data:
- Chain data: 5 minutes
- TVL history: 15 minutes
- TPS data: 5 minutes
The application implements several security measures:
- Rate limiting for API endpoints
- Input validation for all parameters
- Security headers via Helmet
- CORS configuration
ISC
The following environment variables are required for the application to function properly:
PORT- The port on which the server will run (default: 5001)HOST- The host on which the server will run (default: 0.0.0.0)NODE_ENV- The environment in which the application is running (development/production)
DEV_MONGODB_URI- MongoDB connection URI for development environmentPROD_MONGODB_URI- MongoDB connection URI for production environment
GLACIER_API_KEY- API key for Glacier API with increased rate limits
-
GLACIER_API_BASE- Base URL for the Glacier API -
GLACIER_API_TIMEOUT- Timeout for Glacier API requests in milliseconds (default: 30000) -
GLACIER_VALIDATORS_ENDPOINT- Endpoint for validators (default: /networks/mainnet/validators) -
GLACIER_L1VALIDATORS_ENDPOINT- Endpoint for L1Validators (default: /networks/mainnet/l1Validators) -
DEFILLAMA_API_BASE- Base URL for the DefiLlama API -
DEFILLAMA_API_TIMEOUT- Timeout for DefiLlama API requests in milliseconds (default: 30000) -
METRICS_API_BASE- Base URL for the Metrics API -
METRICS_API_TIMEOUT- Timeout for Metrics API requests in milliseconds (default: 30000) -
METRICS_RATE_LIMIT- Rate limit for Metrics API requests per minute (default: 20) -
METRICS_RETRY_DELAY- Delay before retrying Metrics API requests in milliseconds (default: 2000) -
METRICS_MAX_RETRIES- Maximum number of retries for Metrics API requests (default: 3)
GLACIER_RATE_LIMIT- Limit for Glacier API requests per minute (default: 10)GLACIER_RETRY_DELAY- Initial delay before retrying Glacier API requests in milliseconds (default: 5000)GLACIER_MAX_RETRIES- Maximum number of retries for Glacier API requests (default: 5)GLACIER_MIN_DELAY- Minimum delay between Glacier API requests in milliseconds (default: 2000)