- TypeScript 99.3%
- Makefile 0.5%
- Dockerfile 0.2%
|
|
||
|---|---|---|
| .github | ||
| .husky | ||
| .vscode | ||
| monitoring | ||
| src | ||
| .env.template | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| .tool-versions | ||
| AGENTS.md | ||
| biome.json | ||
| CHANGELOG.md | ||
| CONTRIBUTING.md | ||
| Dockerfile | ||
| LICENSE | ||
| Makefile | ||
| package.json | ||
| pnpm-lock.yaml | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.mts | ||
Moca API
Moca API provides a unified gateway to interact with multiple blockchain technologies through a single API interface. It is designed to facilitate access to blockchain data from various sources while maintaining security and ease of integration. This project is developed using TypeScript and integrates with third-party blockchain providers via environment-specific configurations.
Features
- Smart Provider Router: Centralized routing system with automatic failover, managing 19+ blockchain networks instantly.
- Strict Rate Limiting (Traffic Cop): Built-in
bottleneckqueues that dynamically throttle requests based on API Tier limits and endpoint weights to prevent429 Too Many Requests. - Stale-While-Revalidate (SWR) Caching: Intelligent
iorediscache integration that serves stale data instantly (0ms latency) while re-fetching from the provider in the background. Strictly capped at 500MB via LRU eviction. - JWT Authentication: Ensures that all endpoints are secured with JWT (JSON Web Tokens), providing a method for protecting routes and endpoints.
Requirements
Before you begin, ensure you have the following installed:
- Node.js (version 14 or higher)
- TypeScript (automatically handled as a project dependency)
Additionally, you will need:
- API keys for accessing third-party blockchain services, which should be specified in the
.envfile. - A valid JWT token for testing endpoints that require authentication.
Installation and Setup
Follow these steps to get your development environment set up:
1. Clone the Repository
git clone https://gitlab.com/mocaapp/moca_api.git
cd moca_api
2. Install dependencies
This project relies on pnpm. Install it globally if you haven't already:
npm install -g pnpm
pnpm install
3. Configure the .env File
Create a .env file at the root of the project. You must supply your specific API Keys and configurations. An example based on envConfig.ts:
# Server
NODE_ENV=development
HOST=localhost
PORT=3000
# Security & Rate Limiting
COMMON_RATE_LIMIT_MAX_REQUESTS=1000
COMMON_RATE_LIMIT_WINDOW_MS=1000
# Authentication (JWT)
JWT_SECRET=your_jwt_secret
JWT_ISS=api.local
JWT_AUD=api
JWT_SWFD=swfd
JWT_PUBLIC_TTL=600
JWT_REG_TTL=3600
JWT_REFRESH_DAYS=7
ANON_ID_COOKIE_NAME=anon
# Redis Cache (Optional, handles SWR caching automatically if provided)
REDIS_URL=redis://localhost:6379
# Blockchain API Providers (Leave empty or fill with valid keys/URLs)
API_MKT_CST= # CoinStats API
API_MKT_CGK= # CoinGecko API
PROV_CFP= # ChainFlip
API_BCK_TSC= # TronScan
API_BCK_BFT= # BlockFrost
API_BCK_DAE= # BlockDaemon
API_BCK_MOR= # Moralis
API_BCK_BC= # Blockchair
RPC_LIQ_ETH= # Ethereum RPC
RPC_LIQ_BNB= # Binance RPC
RPC_LIQ_ARB= # Arbitrum RPC
PROV_TKD= # TokenD
4. Build and Run the project
Compile the TypeScript code into JavaScript:
pnpm run build
- In Development Mode
This will start the server with hot reloading on code changes:
pnpm run start:dev
- In Production Mode
Use the following command to run the server in production mode:
pnpm run start:prod
5. API Endpoints
This server provides several endpoints to interact with its services. The complete and detailed description of these endpoints is available through Swagger. For more details, see the link "host/api/swagger/docs".
6. Testing
Run the automated tests defined in the project using:
npm run test
Contributing
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
Please refer to our Contributing Guide for detailed steps on how you can contribute.