Backend API for D4L, a fantasy meme-token betting platform where users create tokens, register fighters, run battles, and place bets.
This service is built with NestJS, Prisma, PostgreSQL, and EVM smart-contract integrations via ethers.
Core capabilities:
- Wallet-based auth (challenge + signature verification, JWT sessions)
- User management, profile updates, deposits, and withdrawals
- Meme token creation and lifecycle updates
- Fighting arena flow (register fighter, create battle, place bet, end battle, claim rewards)
- History and analytics (PnL, betting history, leaderboards, dashboard)
- Authenticated image upload with static file serving
- Swagger docs at
/api/docs
NestJS(REST API)Prisma+PostgreSQLethers+ deployed contracts (supported networks:sepolia,amoy)JWTauthenticationSwaggerAPI documentationnestjs-pinologging
yarn installCopy .env.example to .env and fill all values:
PORT=<your-backend-port>
DATABASE_URL=<your-postgresql-database-url>
NETWORK=<sepolia-or-amoy>
PLATFORM_PRIVATE_KEY=<your-private-key>
RPC_URL=<your-rpc-url>
JWT_SECRET_KEY=<your-jwt-secret-key>
JWT_EXPIRES_IN=<your-jwt-expires-in>
APP_URL=<your-app-url>
FRONTEND_URL=<your-frontend-url>yarn prisma generate
yarn prisma migrate dev# development (watch mode)
yarn start:dev
# production
yarn build
yarn start:prodServer defaults to:
- API base:
http://localhost:<PORT>/api - Swagger docs:
http://localhost:<PORT>/api/docs - Uploaded files:
http://localhost:<PORT>/uploads/<filename>
yarn build- Build NestJS appyarn start- Start appyarn start:dev- Start in watch modeyarn start:prod- Run compiled appyarn lint- Run ESLint (auto-fix enabled)yarn test- Run unit testsyarn test:e2e- Run e2e testsyarn test:cov- Run test coverage
All endpoints are prefixed with /api.
auth- wallet challenge and signature verificationusers- account, profile, avatar, wallet operationstokens- create/list/get/update token state and transactionsfighting- fighters, battles, bets, rewardshistory- user activity, pnl, leaderboard, dashboardfile-upload- authenticated image upload
Main entities:
UserTokenFighterBattleBetUserHistoryUserPnLBettingHistoryTokenFightingHistoryUserStatistics
See prisma/schema.prisma for full schema and enums.
- CORS allows local frontend origins in development and
FRONTEND_URLin production. - Contract addresses are resolved by
NETWORKfromsrc/contracts/addresses. - Uploaded assets are stored under
uploads/and served statically.
MIT