A payment proxy platform for monetizing APIs using the x402 payment standard
Gate402 enables developers to monetize their APIs with blockchain-based micropayments. By registering an API with Gate402, developers receive a subdomain (e.g., alice-weather.gate402.xyz) that acts as a payment gateway. When clients make requests:
- No payment β Returns
402 Payment Required - Invalid payment β Returns
402 Payment Required - Valid payment β Proxies request to the origin API server
All transactions are logged for comprehensive analytics and revenue tracking.
Gate402 consists of three separate Express.js servers:
- REST API for gateway management
- Analytics endpoints
- User authentication
- Swagger documentation at
/api/docs
- Handles all
*.gate402.xyzwildcard requests - Payment validation and enforcement
- Request proxying to origin servers
- Request logging for analytics
- x402 payment facilitator service
- Handles payment proof generation and validation
- Manages blockchain interactions
Client Request β alice-weather.gate402.xyz/weather
β
[1] Extract subdomain from Host header
β
[2] Lookup Gateway config (Redis cache β PostgreSQL)
β
[3] Check for x402-payment header
β
[4] Validate payment proof (blockchain verification)
β
[5] Proxy to origin server with X-Gate402-Secret header
β
[6] Log request metrics to database
β
Return response to client
- Runtime: Node.js with Bun/npm
- Framework: Express.js (TypeScript)
- Database: PostgreSQL with Prisma ORM
- Cache: Redis
- API Documentation: TSOA with Swagger UI
- Authentication: JWT with Google OAuth
- Node.js 18+ (or Bun)
- PostgreSQL 14+
- Redis 6+
git clone <repository-url>
cd core-engine
npm install
# or
bun installCopy the example environment file:
cp .env.example .envConfigure the following required variables:
NODE_ENV=development
PORT=3000
DATABASE_URL="postgresql://user:password@localhost:5432/gate402"
REDIS_URL="redis://localhost:6379"
# Core engine specific
PROXY_PORT=3030
API_PORT=3031
JWT_SECRET="super-secret-jwt-key-change-me"
FACILITATOR_URL="http://localhost:3033"
DEFAULT_OTP_VALUE=123456 # For development only
# Facilitator specific
FACILITATOR_PORT=3033
FACILITATOR_PRIVATE_KEY=0xYourFacilitatorPrivateKey# Generate Prisma client
npm run prisma:generate
# Run migrations
npm run prisma:migrateAfter running migrations, you need to manually add supported chains and tokens to the database:
Option 1: Using Prisma Studio (Recommended)
npm run prisma:studioThen navigate to the Chain and Token models to add entries.
Development Mode:
# Start Manager API (with hot reload)
npm run dev
# Start Facilitator proxy (in separate terminal)
npm run dev-facilitatorProduction Mode:
# Build TypeScript
npm run build
# Start Manager API
npm start
# Start Facilitator proxy (in separate terminal)
npm run start-facilitatorOnce the server is running, access the interactive Swagger documentation:
http://localhost:3031/api/docs
POST /api/v1/auth/siwe/nonce- Get nonce for SIWE authenticationPOST /api/v1/auth/siwe/verify- Verify SIWE signature and loginPOST /api/v1/auth/siwe/complete-profile- Complete profile after SIWE loginPOST /api/v1/auth/refresh- Refresh access token
POST /api/v1/gateways- Create new gatewayGET /api/v1/gateways- List user's gatewaysGET /api/v1/gateways/:uuid- Get gateway detailsPATCH /api/v1/gateways/:uuid- Update gatewayDELETE /api/v1/gateways/:uuid- Delete gateway
GET /api/v1/analytics/overview- Revenue and usage statisticsGET /api/v1/analytics/daily-stats- Daily aggregated statsGET /api/v1/analytics/request-logs- Individual request logs
GET /api/v1/config/chains- Supported blockchain networksGET /api/v1/config/tokens- Supported payment tokens
core-engine/
βββ src/
β βββ index.ts # Manager API server entry point
β βββ facilitator.ts # Proxy server entry point
β βββ config/ # Configuration (database, Redis, env)
β βββ controllers/ # TSOA controllers (API endpoints)
β βββ middleware/ # Express middleware (auth, proxy, error)
β βββ services/ # Business logic layer
β βββ types/ # TypeScript type definitions
β βββ utils/ # Utility functions
βββ prisma/
β βββ schema.prisma # Database schema
β βββ migrations/ # Database migrations
β βββ seed.ts # Database seeding script
βββ http/ # HTTP request examples for testing
βββ scripts/ # Utility scripts
βββ build/ # Compiled output (generated)
Gate402 uses JWT-based authentication with two token types:
- Access Token: Short-lived (15 minutes), used for API requests
- Refresh Token: Long-lived (7 days), used to obtain new access tokens
Include the access token in the Authorization header:
curl -H "Authorization: Bearer <access_token>" \
http://localhost:3031/api/v1/gateways- Make a request to a Gate402 subdomain
- Receive
402 Payment Requiredresponse with payment details - Send blockchain transaction (USDC on Base)
- Include transaction hash in
x402-paymentheader - Request is validated and proxied to origin
- Register gateway via
/api/v1/gateways - Configure origin URL, price per request, and accepted networks
- Receive subdomain and secret token
- Add secret token validation to your origin API
- Monitor revenue via analytics endpoints
# Lint code
npm run lint
# Format code
npm run formatThe http/ directory contains sample HTTP requests for manual testing with tools like REST Client or HTTPie.
Build and run with Docker:
# Build Manager API image
docker build -t gate402-api -f Dockerfile .
# Build Facilitator proxy image
docker build -t gate402-facilitator -f Dockerfile.facilitator .
# Run containers (example)
docker run -p 3031:3031 --env-file .env gate402-api
docker run -p 3030:3030 --env-file .env gate402-facilitator- User: User accounts with authentication and payout configuration
- Gateway: API gateway configurations (subdomain, pricing, origin)
- RequestLog: Individual request logs for analytics
- DailyStats: Aggregated daily statistics per gateway
- Chain: Supported blockchain networks
- Token: Supported payment tokens
Run npm run prisma:studio to explore the database with Prisma Studio.
| Command | Description |
|---|---|
npm run dev |
Start Manager API with hot reload |
npm run dev-facilitator |
Start Proxy server with hot reload |
npm run build |
Compile TypeScript to JavaScript |
npm start |
Run compiled Manager API |
npm run start-facilitator |
Run compiled Proxy server |
npm run prisma:generate |
Generate Prisma client |
npm run prisma:migrate |
Run database migrations |
npm run prisma:studio |
Open Prisma Studio |
npm run swagger:generate |
Generate TSOA routes and Swagger spec |
npm run lint |
Lint TypeScript files |
npm run format |
Format code with Prettier |
Health Check Endpoint:
curl http://localhost:3031/healthResponse:
{
"status": "ok",
"timestamp": "2026-01-15T12:38:05.000Z"
}| Variable | Description | Required |
|---|---|---|
NODE_ENV |
Environment (development/production) | Yes |
PORT |
General port (fallback) | No (default: 3000) |
API_PORT |
Manager API port | No (default: 3031) |
PROXY_PORT |
Proxy server port | No (default: 3030) |
DATABASE_URL |
PostgreSQL connection string | Yes |
REDIS_URL |
Redis connection string | Yes |
JWT_SECRET |
Secret for JWT tokens | Yes |
FACILITATOR_URL |
x402 facilitator service URL | Yes |
DEFAULT_OTP_VALUE |
Default OTP for development | No (dev only) |
| Variable | Description | Required |
|---|---|---|
FACILITATOR_PORT |
Facilitator server port | No (default: 3033) |
FACILITATOR_PRIVATE_KEY |
Private key for facilitator | Yes |
- Follow TypeScript best practices
- Use Prettier for code formatting
- Run linter before committing
- Update Swagger documentation for API changes
- Add tests for new features
ISC
- x402 Protocol: Payment standard specification
- Gate402 Frontend: Dashboard application for managing gateways
- x402 SDK: Client libraries for making x402 payments
For issues, questions, or contributions, please refer to the project documentation or contact the development team.
Built with β€οΈ using the x402 payment standard