Mirror of https://gitlab.com/BCH2Dev/moca_api, updated every 6 hours. 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.
  • TypeScript 99.3%
  • Makefile 0.5%
  • Dockerfile 0.2%
Find a file
Italo Moca 61bbb76618 Merge branch 'release/v3.3.95' into 'main'
Release: v3.3.95

See merge request mocaapp/moca_api!176
2026-03-16 09:19:57 +00:00
.github Release: v3.3.95 2026-03-16 09:19:57 +00:00
.husky Release: v3.3.95 2026-03-16 09:19:57 +00:00
.vscode Release: v3.3.95 2026-03-16 09:19:57 +00:00
monitoring Release: v3.3.95 2026-03-16 09:19:57 +00:00
src Release: v3.3.95 2026-03-16 09:19:57 +00:00
.env.template Release: v3.3.95 2026-03-16 09:19:57 +00:00
.gitignore Release: v3.3.95 2026-03-16 09:19:57 +00:00
.gitlab-ci.yml Release: v3.3.95 2026-03-16 09:19:57 +00:00
.tool-versions Release: v3.3.95 2026-03-16 09:19:57 +00:00
AGENTS.md Release: v3.3.95 2026-03-16 09:19:57 +00:00
biome.json Release: v3.3.95 2026-03-16 09:19:57 +00:00
CHANGELOG.md Release: v3.3.95 2026-03-16 09:19:57 +00:00
CONTRIBUTING.md Release: v3.3.95 2026-03-16 09:19:57 +00:00
Dockerfile Release: v3.3.95 2026-03-16 09:19:57 +00:00
LICENSE Release: v3.3.95 2026-03-16 09:19:57 +00:00
Makefile Release: v3.3.95 2026-03-16 09:19:57 +00:00
package.json Release: v3.3.95 2026-03-16 09:19:57 +00:00
pnpm-lock.yaml Release: v3.3.95 2026-03-16 09:19:57 +00:00
README.md Release: v3.3.95 2026-03-16 09:19:57 +00:00
tsconfig.json Release: v3.3.95 2026-03-16 09:19:57 +00:00
vite.config.mts Release: v3.3.95 2026-03-16 09:19:57 +00:00

Latest Release pipeline status coverage report Codacy Badge OpenSSF Best Practices Discord

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 bottleneck queues that dynamically throttle requests based on API Tier limits and endpoint weights to prevent 429 Too Many Requests.
  • Stale-While-Revalidate (SWR) Caching: Intelligent ioredis cache 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 .env file.
  • 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.