A local development fork of the Uniswap V3/V4 routing API that runs as a standalone Express.js server. This API uses @uniswap/smart-order-router to find the most efficient routes for token swaps across multiple protocols and chains.
- π Local Development Server - Run the routing API locally without any cloud dependencies
- π Multi-chain Support - Support for Ethereum, Polygon, Optimism, Arbitrum, Base, and more
- π Smart Order Routing - Uses Uniswap's smart-order-router for optimal swap routes
- πΎ SQLite Caching - Local SQLite database for route caching and performance
- π‘οΈ Error Handling - Comprehensive error handling and logging
- π Health Monitoring - Built-in health check endpoints
- Node.js 16+
- npm or yarn
- RPC access to supported blockchain networks
-
Clone the repository:
git clone <repository-url> cd uniswap-routing-api
-
Install dependencies:
npm install
-
Create environment configuration:
cp config.env.example .env
-
Configure your
.envfile with RPC endpoints:# Required: At least one RPC endpoint WEB3_RPC_1=https://eth-mainnet.alchemyapi.io/v2/your-api-key WEB3_RPC_137=https://polygon-mainnet.g.alchemy.com/v2/your-api-key # Optional: Server configuration PORT=3000 DATABASE_PATH=./routing-api.db
-
Build and start the server:
npm run build npm start
Or for development with auto-rebuild:
npm run dev
The server will start on http://localhost:3000
GET /health
Returns server status and version information.
Example Response:
{
"status": "ok",
"timestamp": "2023-12-01T10:00:00.000Z",
"version": "1.0.0"
}GET /quote
Get the best route and quote for a token swap.
Required Parameters:
tokenInAddress- Contract address of the input tokentokenOutAddress- Contract address of the output tokenamount- Amount in smallest unit (e.g., wei for ETH)type- EitherexactInorexactOut
Optional Parameters:
tokenInChainId- Chain ID for input token (default: 1)tokenOutChainId- Chain ID for output token (default: 1)recipient- Address to receive the output tokensslippageTolerance- Slippage tolerance in basis points (default: 50 = 0.5%)deadline- Transaction deadline in seconds from now (default: 1800 = 30 min)
Example Request:
curl "http://localhost:3000/quote?tokenInAddress=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2&tokenOutAddress=0x6B175474E89094C44Da98b954EedeAC495271d0F&amount=1000000000000000000&type=exactIn&tokenInChainId=1&tokenOutChainId=1&slippageTolerance=50"Example Response:
{
"quoteId": "abc123",
"amount": "1000000000000000000",
"quote": "2950000000000000000000",
"quoteGasAdjusted": "2940000000000000000000",
"gasUseEstimate": "150000",
"gasUseEstimateUSD": "12.50",
"methodParameters": {
"calldata": "0x...",
"value": "0x00",
"to": "0x..."
},
"route": [...],
"hitsCachedRoutes": false
}RPC Endpoints - At least one is required:
WEB3_RPC_1=<ethereum-mainnet-rpc> # Ethereum
WEB3_RPC_137=<polygon-rpc> # Polygon
WEB3_RPC_10=<optimism-rpc> # Optimism
WEB3_RPC_42161=<arbitrum-rpc> # Arbitrum One
WEB3_RPC_8453=<base-rpc> # Base
WEB3_RPC_56=<bsc-rpc> # BNB Smart Chain
WEB3_RPC_43114=<avalanche-rpc> # Avalanche
WEB3_RPC_42220=<celo-rpc> # CeloServer Configuration:
PORT=3000 # Server port
DATABASE_PATH=./routing-api.db # SQLite database path
NODE_ENV=development # Environment modeExternal Services:
GQL_URL=https://api.uniswap.org/v1/graphql # Uniswap GraphQL API
TENDERLY_USER=<user> # Tenderly simulation
TENDERLY_PROJECT=<project> # Tenderly simulation
TENDERLY_ACCESS_KEY=<key> # Tenderly simulation| Network | Chain ID | Environment Variable |
|---|---|---|
| Ethereum Mainnet | 1 | WEB3_RPC_1 |
| Ethereum Sepolia | 11155111 | WEB3_RPC_11155111 |
| Polygon | 137 | WEB3_RPC_137 |
| Optimism | 10 | WEB3_RPC_10 |
| Arbitrum One | 42161 | WEB3_RPC_42161 |
| Base | 8453 | WEB3_RPC_8453 |
| BNB Smart Chain | 56 | WEB3_RPC_56 |
| Avalanche | 43114 | WEB3_RPC_43114 |
| Celo | 42220 | WEB3_RPC_42220 |
npm run build # Build the project
npm start # Start the server
npm run dev # Build and start with auto-reload
npm run watch # Watch for changes and rebuild
npm run clean # Clean build directorynpm run test:unit # Run unit tests
npm run test:integ # Run integration tests
npm run test:e2e # Run end-to-end testsnpm run fix # Fix linting and formatting issues
npm run fix:prettier # Fix formatting with Prettier
npm run fix:lint # Fix linting with ESLint- Express.js Server - RESTful API server with CORS support
- SQLite Database - Local caching for routes and token data
- Smart Order Router - Uniswap's routing algorithm for optimal paths
- Multi-chain Support - Configurable RPC providers for different networks
The API returns structured error responses:
{
"errorCode": "QUOTE_ERROR",
"detail": "No route found for the given parameters"
}Common error codes:
QUOTE_ERROR- Quote generation failedINTERNAL_ERROR- Server errorNOT_FOUND- Endpoint not found
- Route Caching - Routes are cached in SQLite for faster responses
- Connection Pooling - Efficient RPC connection management
- Gas Optimization - Smart gas estimation and optimization
- WETH:
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 - USDC:
0xA0b86a33E6417058256Ce9DEd69BcF4C8C02AA9B - USDT:
0xdAC17F958D2ee523a2206206994597C13D831ec7 - DAI:
0x6B175474E89094C44Da98b954EedeAC495271d0F - UNI:
0x1f9840a85d5af5bf1d1762f925bdaddc4201f984
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Run
npm run fixto ensure code quality - Submit a pull request
GPL - See LICENSE file for details