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": "0x0A8d670EBE6a01Ed1623eA13Dd928e66051c8147",
        "price": "1.00",
        "decimals": 8
      },
      {
        "symbol": "WETH",
        "name": "Wrapped Ether",
        "address": "0x1875f28FfABbf325C75544FC30Dbb920b33619eE",
        "price": "2500.00",
        "decimals": 8
      },
      {
        "symbol": "WBTC",
        "name": "Wrapped Bitcoin",
        "address": "0xE78b8806b3f9833C3A3fDC942D3F9cE304946cfC",
        "price": "45000.00",
        "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://sepolia-rollup.arbitrum.io/rpc
CHAIN_ID=421614
REDIS_HOST=localhost
REDIS_PORT=6379
PRICE_CACHE_TTL=60

Supported Tokens

SymbolNameOracle
USDCUSD Coin0x015300...
WETHWrapped Ether0xd30e21...
WBTCWrapped Bitcoin0x56a43E...
CRYPTOPUNKSCryptoPunks0xC7e820...

Error Handling

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