GET /api/v1/quote
Fetch the best swap route with MEV-protected transaction parameters by querying multiple DEX aggregators (1inch, KyberSwap, ParaSwap, Uniswap V3) and returning the optimal execution path.
Endpoint Details
GET https://api.unikron.ch/api/v1/quoteAuthentication Required: Yes (API Key via X-API-Key header)
Request Parameters
Query Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
sellToken | string | Yes | Token contract address to sell (EIP-55 checksummed) | 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 |
buyToken | string | Yes | Token contract address to buy (EIP-55 checksummed) | 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 |
sellAmount | string | Yes | Amount in smallest units (wei for 18 decimals) | 1000000000000000000 (1 WETH) |
userAddress | string | Yes | User’s wallet address (for gas estimation & tx building) | 0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb |
chainId | number | No | Chain ID (default: 1 for Ethereum mainnet) | 1 |
slippageBps | number | No | Slippage tolerance in basis points (default: 50) | 100 (1%) |
Headers
| Header | Required | Description | Example |
|---|---|---|---|
X-API-Key | Yes | Your UNIKRON API key | uk_live_abc123... |
Important Requirements
Native ETH Not Supported You cannot use native ETH addresses. Always
use WETH instead: - 0x0000000000000000000000000000000000000000 Not
Supported - 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE Not Supported -
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 (WETH) Supported
Amount Precision Always use smallest denominated units: - 18-decimal
tokens (WETH, DAI): 1000000000000000000 = 1 token - 6-decimal tokens (USDC,
USDT): 1000000 = 1 token - Use ethers.parseEther() or Web3.to_wei() for
conversion
Address Format All addresses must be EIP-55 checksummed format (mixed
case): - Example: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 - Invalid:
0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Code Examples
cURL
cURL
curl -X GET "https://api.unikron.ch/api/v1/quote?\
sellToken=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2&\
buyToken=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&\
sellAmount=1000000000000000000&\
userAddress=0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb&\
chainId=1" \
-H "X-API-Key: YOUR_API_KEY" \Response Format
Success Response (200 OK)
{
"ok": true,
"data": {
"source": "UniswapV3",
"sellToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"buyToken": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"sellAmount": "9184150611730736",
"buyAmount": "31630819",
"minBuyAmount": "31311379",
"estimatedGas": 90022,
"priceImpact": 0.0417,
"dexRoute": {
"dex": "UniswapV3",
"target": "0xE592427A0AEce92De3Edee1F18E0157C05861564",
"path": [
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
]
},
"scoring": {
"netValueUsd": 31.43,
"gasCostUsd": 0.2
},
"alternatives": [
{
"source": "ParaSwap",
"buyAmount": "31505328",
"netValueUsd": 31.28
}
],
"mevAnalysis": {
"threatLevel": "MEDIUM",
"estimatedProtectionUsd": 0.0068
},
"mevProtection": {
"provider": "MEV Blocker",
"transactionParams": {
"to": "0xE592427A0AEce92De3Edee1F18E0157C05861564",
"data": "0x414bf389000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000008cf3f9892f0cc5119f1dcd91ebcd6a8fe4b0d34200000000000000000000000000000000000000000000000000000000690e4fd80000000000000000000000000000000000000000000000000020a0efb2c6a1300000000000000000000000000000000000000000000000000000000001ddc6130000000000000000000000000000000000000000000000000000000000000000",
"value": "0",
"gasLimit": "135033",
"maxFeePerGas": "3312120056",
"maxPriorityFeePerGas": "0",
"nonce": 55,
"chainId": 1,
"type": 2
},
"providerMetadata": {
"provider": "mev_blocker",
"tier": 2,
"mevBlockerMetadata": {
"endpoint": "https://rpc.mevblocker.io/fast?shareAll=1&referrer=UNIKRON&refundRecipient=0xEd7B89a1F7d00BD7c631D570a09bcE596D40d58F",
"endpointType": "fast",
"expectedRebate": 0.142,
"shareMode": "shareSafe",
"revertProtection": false,
"useBoost": false
}
}
}
},
"timestamp": 1762544727251
}Response Fields Reference
Root Level
| Field | Type | Description |
|---|---|---|
ok | bool | Request success indicator (true on success) |
data | object | Quote data object (see below) |
timestamp | number | Unix timestamp in milliseconds |
Quote Data Object
| Field | Type | Description |
|---|---|---|
source | string | Winning DEX aggregator (KyberSwap, 1inch, ParaSwap, Uniswap) |
sellToken | string | Token being sold (checksummed address) |
buyToken | string | Token being bought (checksummed address) |
sellAmount | string | Input amount in smallest units |
buyAmount | string | Expected output amount (before slippage) |
minBuyAmount | string | Minimum acceptable output (with 0.6% slippage tolerance) |
estimatedGas | number | Estimated gas consumption in units |
priceImpact | number | Price impact percentage (0.12 = 0.12%) |
dexRoute | object | DEX routing information |
scoring | object | Value scoring metrics |
alternatives | array | Alternative routes with lower prices |
mevAnalysis | object | MEV threat analysis |
mevProtection | object | MEV protection details & transaction params |
DEX Route Object
| Field | Type | Description |
|---|---|---|
dex | string | Selected DEX name |
target | string | ⚠️ Router address (approve tokens to this address) |
path | array | Token swap path |
data | string | Encoded swap calldata (immutable, do not modify) |
Scoring Object
| Field | Type | Description |
|---|---|---|
netValueUsd | number | Net value after fees (USD) |
gasCostUsd | number | Estimated gas cost (USD) |
MEV Protection Object
| Field | Type | Description |
|---|---|---|
provider | string | MEV protection service (e.g., “MEV Blocker”) |
transactionParams | object | Complete EIP-1559 transaction ready for signing |
providerMetadata | object | MEV provider configuration (required for order submission - see next table) |
Transaction Parameters (Sign These)
| Field | Type | Description |
|---|---|---|
to | string | Target contract address |
data | string | Transaction calldata |
value | string | ETH value (“0” for ERC-20 swaps) |
gasLimit | string | Maximum gas limit |
maxFeePerGas | string | Maximum fee per gas unit (wei) |
maxPriorityFeePerGas | string | Priority fee (always “0” for MEV protection) |
nonce | number | Transaction nonce |
chainId | number | Network chain ID (1 = Ethereum mainnet) |
type | number | Transaction type (2 = EIP-1559) |
Provider Metadata (For Order Submission)
Required for Order Submission - The providerMetadata object must be passed to the order submission endpoint (POST /api/v1/mev/orders) along with the signed transaction. Do not modify these values.
| Field | Type | Description |
|---|---|---|
provider | string | Provider identifier (“mev_blocker”) |
tier | number | Protection tier (2 or 4) |
mevBlockerMetadata | object | MEV Blocker specific configuration |
MEV Blocker Metadata
| Field | Type | Description |
|---|---|---|
endpoint | string | MEV Blocker RPC endpoint with query params |
endpointType | string | Endpoint type (fast, noreverts, fullprivacy) |
expectedRebate | number | Expected MEV rebate in USD |
shareMode | string | Sharing mode (shareAll, shareSafe, none) |
revertProtection | boolean | Whether revert protection is enabled |
useBoost | boolean | Whether boost mode is enabled (always false with zero priority fee) |
Error Responses
400 Bad Request
{
"ok": false,
"error": "INVALID_TOKEN_ADDRESS",
"message": "sellToken must be a valid checksummed address",
"details": {
"field": "sellToken",
"provided": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"reason": "Invalid checksum"
}
}401 Unauthorized
{
"ok": false,
"error": "UNAUTHORIZED",
"message": "Invalid or missing API key",
"suggestion": "Check your X-API-Key header"
}404 Not Found
{
"ok": false,
"error": "INSUFFICIENT_LIQUIDITY",
"message": "No route found for this token pair",
"suggestion": "Try reducing the swap amount or check token addresses"
}429 Rate Limit Exceeded
{
"ok": false,
"error": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded for API key",
"retryAfter": 30,
"limit": 300,
"window": 60
}Common Error Codes
| HTTP | Error Code | Reason | Solution |
|---|---|---|---|
| 400 | INVALID_TOKEN_ADDRESS | Invalid address format/checksum | Use EIP-55 checksummed addresses |
| 400 | NATIVE_ETH_NOT_SUPPORTED | Used ETH instead of WETH | Use WETH address instead |
| 400 | INVALID_AMOUNT | Amount is 0 or negative | Provide positive amount in wei |
| 400 | USER_ADDRESS_REQUIRED | Missing user parameter | Add user wallet address to request |
| 401 | UNAUTHORIZED | Invalid/missing API key | Check X-API-Key header |
| 404 | INSUFFICIENT_LIQUIDITY | No route found | Try smaller amount or different pair |
| 404 | TOKEN_NOT_SUPPORTED | Token not supported | Check supported token list |
| 429 | RATE_LIMIT_EXCEEDED | Too many requests | Wait and retry with backoff |
| 500 | INTERNAL_SERVER_ERROR | Server error | Retry with exponential backoff |
| 503 | SERVICE_UNAVAILABLE | Upstream aggregator down | Retry after a few seconds |
Integration Workflow
After receiving a quote, follow these steps:
1. Check Token Approval
const allowance = await tokenContract.allowance(
userAddress,
quote.dexRoute.target // ⚠️ Use this address
);
if (allowance < sellAmount) {
// Need approval - see step 2
}2. Approve Tokens
See: Token Approval Guide
await tokenContract.approve(quote.dexRoute.target, ethers.MaxUint256);3. Sign Transaction
See: Sign & Submit Guide
// Sign the transaction params
const signedTx = await signer.signTransaction(
quote.mevProtection.transactionParams
);4. Submit Order
// IMPORTANT: Include both signedTransaction AND providerMetadata
const order = await fetch(`${API_URL}/api/v1/mev/orders`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": API_KEY,
},
body: JSON.stringify({
orderParams: {
fromToken: quote.sellToken,
toToken: quote.buyToken,
amount: quote.sellAmount,
minReturnAmount: quote.minBuyAmount,
userAddress: userAddress,
chainId: 1,
deadline: Math.floor(Date.now() / 1000) + 1800,
slippageBps: 100,
selectedTier: 2,
threatAnalysis: {
threatScore: quote.mevAnalysis.threatLevel === "HIGH" ? 0.8 :
quote.mevAnalysis.threatLevel === "MEDIUM" ? 0.5 : 0.2,
threatLevel: quote.mevAnalysis.threatLevel,
confidence: 0.8,
riskFactors: [],
estimatedSavings: {
estimatedProtection: {
amount: quote.mevAnalysis.estimatedProtectionUsd,
currency: "USD"
}
},
timestamp: Date.now()
},
transactionValueUsd: quote.scoring.netValueUsd,
dexRoute: quote.dexRoute,
},
signedTransaction: signedTx,
providerMetadata: quote.mevProtection.providerMetadata, // ⚠️ Required!
}),
});5. Monitor Status
See: Get Order Status Endpoint
const status = await fetch(`${API_URL}/api/v1/mev/orders/${order.orderId}`);Best Practices
MEV Protection Transaction Signing
Sign the transaction using transactionParams and preserve providerMetadata for order submission:
// Sign the transaction
const signedTx = await signer.signTransaction(
quote.mevProtection.transactionParams
);
// Keep providerMetadata for order submission (DO NOT modify)
const providerMetadata = quote.mevProtection.providerMetadata;Critical: Always pass providerMetadata when submitting orders. This contains the MEV Blocker endpoint configuration, referral codes, and rebate settings. The order will fail without it.
Zero Priority Fees for MEV Protection
Gas Optimization: All MEV-protected transactions use maxPriorityFeePerGas: "0". MEV Blocker handles transaction ordering through private mempool routing, so priority fees (tips) are not needed. This saves you money on every transaction.
Quote Validity
Quotes expire after ~30 seconds due to market volatility
Always request a fresh quote before executing a swap. Do not cache quotes for extended periods.
Error Handling
try {
const quote = await getQuote(...);
} catch (error) {
if (error.message.includes('INSUFFICIENT_LIQUIDITY')) {
// Try smaller amount
} else if (error.message.includes('RATE_LIMIT')) {
// Implement exponential backoff
} else {
// Handle other errors
}
}Rate Limiting
- Implement client-side rate limiting
- Use exponential backoff on 429 responses
- Cache quote responses (max 30 seconds)
- Monitor
X-RateLimit-*headers
Gas Estimation
const totalCostWei =
BigInt(quote.estimatedGas) *
BigInt(quote.mevProtection.transactionParams.maxFeePerGas);
const totalCostEth = ethers.formatEther(totalCostWei);
console.log(`Estimated gas cost: ${totalCostEth} ETH`);Related Endpoints
- POST /api/v1/mev/orders - Submit signed transaction
- GET /api/v1/mev/orders/:orderId - Check order status
- POST /api/v1/mev/wrap/quote - Get WETH wrap/unwrap quote