Skip to main content

Overview

Express.js API with Redis caching for fetching token prices from on-chain oracles. Base URL: http://localhost:3001/api

Health Check

GET /api/health
Response:
{
  "status": "ok",
  "redis": "connected",
  "blockchain": "connected"
}

Get All Prices

GET /api/prices
Query Parameters:
ParamTypeDescription
cachebooleanSet false to bypass cache
Response:
{
  "success": true,
  "data": {
    "prices": [
      {
        "symbol": "USDC",
        "name": "USD Coin",
        "address": "0x8B604C1c5a5a821d6f14baf9c1D91D5b21A3f9Eb",
        "price": "1.00",
        "decimals": 8
      },
      {
        "symbol": "WETH",
        "name": "Wrapped Ether",
        "address": "0x2437d7a10064005a9Ce3667e8Ad4382C5C9A4404",
        "price": "2500.00",
        "decimals": 8
      },
      {
        "symbol": "WBTC",
        "name": "Wrapped Bitcoin",
        "address": "0x0Af7005696bCD6F721dD9e8F10aBD351383e10A5",
        "price": "45000.00",
        "decimals": 8
      },
      {
        "symbol": "IDRX",
        "name": "Indonesian Rupiah Token",
        "address": "0x056620afe01E33802ce50637438677Dc7b4841E0",
        "price": "0.000065",
        "decimals": 8
      }
    ],
    "timestamp": 1701234567890,
    "cached": true
  }
}

Get Price by Symbol

GET /api/prices/:symbol
Example:
curl http://localhost:3001/api/prices/weth
Response:
{
  "success": true,
  "data": {
    "symbol": "WETH",
    "name": "Wrapped Ether",
    "price": "2500.00",
    "decimals": 8
  }
}

Refresh Prices

POST /api/prices/refresh
Forces a cache refresh for all token prices.

Configuration

Environment Variables

PORT=3001
NODE_ENV=development
RPC_URL=https://rpc.testnet.story.foundation
CHAIN_ID=1315
REDIS_HOST=localhost
REDIS_PORT=6379
PRICE_CACHE_TTL=60

Supported Tokens

SymbolNameOracle
USDCUSD Coin0x97779d...
WETHWrapped Ether0x278131...
WBTCWrapped Bitcoin0x909cC3...
IDRXIndonesian Rupiah0x9A9B80...
CRYPTOPUNKSCryptoPunks IP0x75837e...

Error Handling

{
  "success": false,
  "error": "Token not found"
}
HTTP status codes:
  • 200 - Success
  • 400 - Bad request
  • 404 - Not found
  • 500 - Server error