A Node.js backend application for managing Solana wallet registrations and token purchases.
- User registration with Solana wallet address
- JWT-based authentication
- Token purchase tracking
- Purchase history management
- Node.js (v14 or higher)
- MongoDB
- npm or yarn
- Clone the repository
- Install dependencies:
npm install
- Create a
.envfile in the root directory with the following variables:PORT=3000 MONGODB_URI=mongodb://localhost:27017/sol-ico JWT_SECRET=your_jwt_secret_key_here JWT_EXPIRES_IN=7d - Start the server:
npm run dev
-
POST /api/auth/register- Register a new user with Solana wallet address
- Body:
{ "walletAddress": "your_solana_wallet_address" }
-
POST /api/auth/login- Login with Solana wallet address
- Body:
{ "walletAddress": "your_solana_wallet_address" }
-
POST /api/purchases- Create a new purchase record
- Headers:
Authorization: Bearer <token> - Body:
{ "tokenPurchased": 100, "presaleActivePhase": 1, "usdtSent": 1000, "transactionHash": "transaction_hash_here" }
-
GET /api/purchases/my-purchases- Get current user's purchase history
- Headers:
Authorization: Bearer <token>
-
GET /api/purchases/all- Get all purchases (admin only)
- Headers:
Authorization: Bearer <token>
- JWT-based authentication
- Protected routes
- Input validation
- Error handling
The API returns appropriate HTTP status codes and error messages in case of failures:
- 400: Bad Request
- 401: Unauthorized
- 404: Not Found
- 500: Internal Server Error