A robust Node.js Express backend for Web3 applications with MongoDB integration, supporting multiple blockchain networks (Ethereum, Polygon, BSC).
- 🔐 JWT Authentication & Wallet-based Authentication
- 🌐 Multi-network support (Ethereum, Polygon, BSC)
- 💾 MongoDB integration with Mongoose
- 🔒 Security middleware (Helmet, CORS, Rate limiting)
- ✅ Input validation with express-validator
- 📊 Transaction tracking and wallet management
- 🚀 RESTful API design
- 🧪 Test-ready structure
- Runtime: Node.js (>=18.0.0)
- Framework: Express.js
- Database: MongoDB with Mongoose
- Blockchain: Web3.js & Ethers.js
- Authentication: JWT & Wallet signatures
- Validation: express-validator
- Security: Helmet, CORS, bcryptjs
- Node.js (>=18.0.0)
- MongoDB
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd backend- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env
# Edit .env with your configuration- Start MongoDB (if running locally):
mongod- Run the application:
# Development mode
npm run dev
# Production mode
npm startThe server will start on http://localhost:3000 (or your configured PORT).
Copy .env.example to .env and configure:
MONGODB_URI: MongoDB connection stringJWT_SECRET: Secret key for JWT tokensETHEREUM_RPC_URL: Ethereum RPC endpointPOLYGON_RPC_URL: Polygon RPC endpointBSC_RPC_URL: BSC RPC endpoint
POST /api/auth/register- Register userPOST /api/auth/login- Login userPOST /api/auth/wallet-login- Login with wallet signatureGET /api/auth/me- Get current userPUT /api/auth/profile- Update profile
GET /api/wallets- Get user walletsPOST /api/wallets- Add walletGET /api/wallets/:address- Get wallet detailsGET /api/wallets/:address/balance- Get wallet balanceGET /api/wallets/:address/transactions- Get wallet transactions
GET /api/transactions- Get transactionsPOST /api/transactions- Create transactionGET /api/transactions/:txHash- Get transaction detailsGET /api/transactions/stats- Get transaction statistics
GET /api/web3/networks- Get supported networksGET /api/web3/gas-price- Get current gas pricePOST /api/web3/estimate-gas- Estimate gas for transactionGET /api/web3/balance- Get wallet balance
GET /api/users- Get users (admin only)GET /api/users/:id- Get user by IDPUT /api/users/:id- Update user
src/
├── config/
│ ├── database.js # MongoDB connection
│ └── web3.js # Web3 configuration
├── middleware/
│ ├── auth.js # Authentication middleware
│ ├── errorHandler.js # Error handling
│ └── validation.js # Input validation
├── models/
│ ├── User.js # User model
│ ├── Wallet.js # Wallet model
│ └── Transaction.js # Transaction model
├── routes/
│ ├── index.js # Main router
│ ├── auth.js # Auth routes
│ ├── users.js # User routes
│ ├── wallets.js # Wallet routes
│ ├── transactions.js # Transaction routes
│ └── web3.js # Web3 routes
├── controllers/ # Route controllers (to be implemented)
└── server.js # Main server file
npm run dev- Start development server with nodemonnpm start- Start production servernpm test- Run testsnpm run lint- Run ESLintnpm run lint:fix- Fix ESLint issues
The route files are set up but controllers need to be implemented. Create controller files in src/controllers/:
authController.jsuserController.jswalletController.jstransactionController.jsweb3Controller.js
- JWT token authentication
- Wallet signature verification
- Password hashing with bcrypt
- Rate limiting
- CORS protection
- Helmet security headers
- Input validation and sanitization
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License