This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
The Shardeum JSON-RPC Server provides an EVM-compatible API interface for interacting with the Shardeum blockchain. It bridges dapps with the blockchain through HTTP/WebSocket endpoints.
# Development
npm install
npm run dev # Runs with nodemon for auto-reload
# Production
npm run compile
npm run start
# Docker (recommended for production)
docker compose up -d# Run all tests
npm test
# Run a single test file
npm test -- test/unit/path/to/test.test.ts# Linting
npm run lint
# Formatting
npm run format-check # Check formatting
npm run format-fix # Auto-fix formatting- Server Entry (
src/server.ts): Express server with Jayson JSON-RPC handling and WebSocket support - API Implementation (
src/api.ts): EVM-compatible JSON-RPC methods implementation - External Services Integration:
- Archiver: Historical blockchain data (configured via
archiverUrl) - Collector: Data aggregation service
- Service Validator: Transaction validation
- Archiver: Historical blockchain data (configured via
- Middleware Pipeline: IP injection → Rate limiting → Method whitelist → Request logging → Authentication
- Round-Robin Node Selection: Distributes load across consensus nodes
- Caching Strategy: Block caching with configurable size limits
- Security Layers: Rate limiting per IP/address, spammer detection, debug endpoint protection
Main configuration in src/config.ts with environment variable overrides:
RPC_PORT: Server port (default: 8080)ARCHIVER_IP/ARCHIVER_PORT: Archiver connectionLOG_SAVE_TO_DATABASE: Enable request loggingRATE_LIMIT: Enable rate limitingSPAM_DETECTION: Enable spammer detection
- Located in
src/websocket/ - Supports
eth_subscribefor newHeads and logs - Connection limits: 1000 total, 50 subscriptions per socket
- Automatic cleanup on disconnect
- All SQL queries use parameterized statements
- Rate limiting: 10 transactions per 2 minutes per address
- IP blacklisting support via
blacklist.json - Developer authentication via public keys in
devPublicKeys.json
- Jest with TypeScript (config in
jest.config.js) - Unit tests in
test/unit/ - High timeout (5s) for integration-style tests
- Coverage reporting enabled by default
Three available methods (configurable via gasEstimationMethod):
serviceValidator: Uses external validator servicereplayEngine: Replays transaction for accurate estimationvalidator: Direct validator node query
- SQLite for local storage
- Schema initialization in
src/storage/ - Request logging table for analytics
- PM2 support for process management
- Docker deployment uses host network mode
- Configurable replica count for scaling
- Health check endpoint at
/health