A production-grade backend service for simulating transactions on HyperEVM networks.
- Transaction Simulation: Simulate transactions with detailed call traces
- Contract Metadata: Fetch and cache contract ABIs and metadata
- Access List Generation: Generate EIP-2930 access lists for transactions
- Production Ready: Built with enterprise-grade patterns and practices
- Comprehensive Logging: Structured logging with Winston
- Error Handling: Custom error classes with proper HTTP status codes
- Rate Limiting: Built-in rate limiting to prevent abuse
- Security: Helmet.js security headers and input validation
- Monitoring: Health checks and metrics endpoints
The application follows a clean, scalable architecture with the following components:
- SimulationService: Main simulation logic and response formatting
- RPCService: Blockchain RPC communication with retry logic
- ContractMetadataService: Contract metadata fetching and caching
- Logger: Centralized logging with Winston
- Error Handling: Custom error classes and middleware
- Validation: Request validation using Joi
- Configuration: Environment-based configuration management
- Security: Helmet.js, CORS, rate limiting
- Logging: Morgan HTTP request logging
- Error Handling: Global error handler and 404 handler
# Install dependencies
npm install
# Copy environment variables
cp .env.example .env
# Build the application
npm run build
# Start the application
npm startCreate a .env file with the following variables:
NODE_ENV=development
PORT=4000
HYPEREVM_RPC_URL=https://sepolia.drpc.org
LOG_LEVEL=info
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100
CORS_ORIGIN=*
REQUEST_TIMEOUT_MS=30000
MAX_REQUEST_SIZE=10mbGET /healthReturns the health status of the service.
POST /api/simulation/simulate
Content-Type: application/json
{
"from": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
"to": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
"input": "0x",
"value": "0x0",
"gas": 1000000,
"gasPrice": "0x3b9aca00",
"networkId": "11155111",
"blockNumber": "latest",
"generateAccessList": true
}GET /api/simulation/healthReturns the health status of the simulation service.
# Start development server with hot reload
npm run dev
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Lint code
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run format
# Type checking
npm run type-checkThe application includes comprehensive tests:
# Run all tests
npm test
# Run tests with coverage
npm test -- --coverage
# Run specific test file
npm test -- simulation.test.tsFROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY dist ./dist
EXPOSE 4000
CMD ["node", "dist/index.js"]- Set
NODE_ENV=production - Configure proper RPC endpoints
- Set up monitoring and logging
- Configure rate limiting based on your needs
- Set up health checks and load balancing
/health- Application health/api/simulation/health- Simulation service health
The application uses structured logging with the following levels:
error- Application errorswarn- Warning messagesinfo- General informationdebug- Debug information
Consider adding Prometheus metrics for:
- Request count and duration
- Error rates
- RPC call metrics
- Cache hit rates
The application uses custom error classes:
AppError- Base error classRPCError- RPC communication errorsValidationError- Input validation errorsSimulationError- Simulation-specific errorsContractMetadataError- Contract metadata errorsRateLimitError- Rate limiting errors
- Input Validation: All inputs are validated using Joi schemas
- Rate Limiting: Built-in rate limiting to prevent abuse
- Security Headers: Helmet.js provides security headers
- CORS: Configurable CORS settings
- Request Size Limits: Configurable request size limits
- Caching: Contract metadata is cached with TTL
- Parallel Processing: Multiple RPC calls are made in parallel
- Connection Pooling: HTTP client with connection pooling
- Compression: Response compression enabled
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run linting and tests
- Submit a pull request
MIT License