A NestJS-based REST API for converting cryptocurrency tokens and fiat currencies.
This API provides two endpoints for conversion:
- Token Conversion (
/token) - Convert between cryptocurrency tokens - Currency Conversion (
/currency) - Convert between fiat currencies
# Using bun
bun install# Development mode
bun run start:dev
# Production mode
bun run start:prod
# Build
bun run buildThe server will start on http://localhost:3000 by default.
Endpoint: GET /token
Query Parameters:
from(required) - Source token address (must be valid Solana address)to(required) - Target token address (must be valid Solana address)amount(optional) - Amount to convert (default: 1)
Example Requests:
# SOL to USDC conversion
curl "http://localhost:3000/token?from=sol&to=usdc"
# With amount
curl "http://localhost:3000/token?from=sol&to=usdc&amount=5"Response:
{
"from": "sol",
"to": "usdc",
"amount": 5,
"convertedAmount": 1096.7758175266744,
"timestamp": 1728561296789
}Error Responses:
{
"statusCode": 400,
"message": "Invalid token address: from",
"error": "Bad Request"
}{
"statusCode": 404,
"message": "Token doesn't exist: So111...",
"error": "Not Found"
}Endpoint: GET /currency
Query Parameters:
from(required) - Source currency code (must be valid currency)to(required) - Target currency code (must be valid currency)amount(optional) - Amount to convert (default: 1)
Supported Currencies:
usd, eur, gbp, jpy, chf, cad, aud, nzd, cny, inr, krw, sgd, hkd, sek, nok, dkk, pln, thb, myr, zar, brl, mxn, rub, try, aed, sar, idr, php, vnd, egp
Example Requests:
# Basic conversion
curl "http://localhost:3000/currency?from=usd&to=eur"
# With amount
curl "http://localhost:3000/currency?from=usd&to=eur&amount=100"
# Different currencies
curl "http://localhost:3000/currency?from=gbp&to=jpy&amount=50"Response:
{
"from": "usd",
"to": "eur",
"amount": 100,
"convertedAmount": 92.15,
"timestamp": 1728561296789
}Error Response (Invalid Currency):
{
"statusCode": 400,
"message": "Invalid 'from' currency: xyz",
"error": "Bad Request"
}- Token endpoint (
/token) returns real-time prices from Jupiter Price API- Requires valid Solana token addresses (base58 format)
- Validates addresses using @solana/web3.js
- Calculates conversion using USD prices:
amount * (fromPrice / toPrice)
- Currency endpoint (
/currency) returns real-time exchange rates from fawazahmed0 currency API- Currency codes must be lowercase
- Validates against a predefined list of supported currencies
- Has fallback URL support for reliability
- All responses include a
timestampfield with Unix epoch time in milliseconds