Deployed Link: https://koinx-backend-internship-assignment.onrender.com/
Postman API's Collection: https://grey-station-125149-1.postman.co/workspace/koinx-public~2a6b5193-eb34-40c1-ae66-34ae587c820a/collection/21207467-0e42b0b5-3878-4f1b-924c-bb476abe80ec?action=share&creator=21207467
This project is a Node.js server application developed as part of assignment for the Koinx Backend Developer Internship. The application fetches cryptocurrency transactions for a user, stores them in a MongoDB database, retrieves Ethereum price data, and calculates the total expenses for the user's transactions.
- Node.js
- Express.js
- MongoDB (Mongoose)
- Axios
- Node-Cron
- Etherscan API
- CoinGecko API
================================================================
================================================================
-
Clone the Repository:
git clone https://github.com/nandk4552/koinx_backend_internship_assignment.git cd koinx_backend_internship_assignment
-
Install Dependencies:
npm install
-
Set Up Environment Variables: Create a .env file in the root directory and add the following:
MONGO_URI=your_mongodb_connection_string PORT=your_desired_port_number ETHERSCAN_API_KEY=your_etherscan_api_key JWT_SECRET=your_jwt_secret
-
Set Up Environment Variables:
npm run dev
The server will start on http://localhost:8080.
[Note]: Before Accessing API create a user and login and use the token generated in headers with naming convention Bearer {paste token w/o braces}
Endpoint: GET /api/v1/transactions/:address
Description: Fetches the list of "Normal" transactions for a given user address and stores them in the database.
Parameters: :address (string): The user's Ethereum address.
Response: Returns a list of transactions for the given address.
Example Request:
GET /api/v1/transactions/0xce94e5621a5f7068253c42558c147480f38b5e0d
Cron Job: This task is handled automatically by a cron job that runs every 10 minutes. Description: Fetches the current price of Ethereum in INR from the CoinGecko API and stores it in the database.
Endpoint: This task does not have a direct API endpoint as it is automated by the cron job.
Endpoint: GET /api/v1/expenses/:address
Description: Calculates the total expenses for a user's transactions based on (gasUsed * gasPrice) / 1e18, retrieves the current Ethereum price, and returns both. Parameters: :address (string): The user's Ethereum address. Response: totalExpenses: The total expense for all transactions. currentEthereumPrice: The latest Ethereum price in INR. Example Request:
GET /api/v1/expenses/0xce94e5621a5f7068253c42558c147480f38b5e0d
Cron Job The cron job is set up to run every 10 minutes and fetch the current price of Ethereum. It logs the price and stores it in the MongoDB database.