This is an API server for managing Solana wallets, built with Node.js, Express, and TypeScript. The server provides robust functionality for:
- User signup
- Network switching
- Balance checking
- SOL transfers
It seamlessly interacts with a MongoDB database to store user information and wallet details.
-
Clone the repository:
git clone <repository-url> cd backend
-
Install dependencies:
npm install
-
Build the project:
npm run build
Create a .env
file in the backend
directory with the following variables:
PORT=3000
MONGO_URI=your_mongodb_uri
API_TOKEN=your_api_token
- Endpoint:
/api/signup
- Method:
POST
- Description: Signup and create a new Solana wallet
Request Body:
{
"telegramId": "string",
"password": "string",
"name": "string"
}
Response:
{
"message": "User created",
"mnemonic": "string",
"publicKey": "string",
"privateKey": "string"
}
- Endpoint:
/api/network/switch
- Method:
POST
- Description: Switch to mainnet, devnet, or connect to Solana blockchain using a custom RPC URL
Request Body:
{
"telegramId": "string",
"password": "string",
"network": "string",
"rpcUrl": "string" // required if network is 'custom'
}
Response:
{
"message": "Network switched successfully"
}
- Endpoint:
/api/balance
- Method:
POST
- Description: Get the native SOL balance of a wallet
Request Body:
{
"telegramId": "string",
"password": "string",
"walletName": "string"
}
Response:
{
"balance": "number"
}
- Endpoint:
/api/transfer
- Method:
POST
- Description: Transfer SOL to another wallet
Request Body:
{
"telegramId": "string",
"password": "string",
"to": "string",
"amount": "number",
"walletName": "string"
}
Response:
{
"signature": "string"
}
- File:
access.ts
- Description: Validates the API token in the request body
- File:
auth.ts
- Description: Authenticates the user based on the telegram ID and password
- File:
userModel.ts
- Description: Defines the schema for user documents in MongoDB
- File:
userController.ts
- Description: Handles user-related operations such as signup
- File:
txnController.ts
- Description: Handles transaction-related operations such as:
- Network switching
- Balance checking
- SOL transfers
-
Start the backend server:
npm run start
-
Expose the server on the internet using ngrok:
ngrok http http://localhost:3000
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.