Skip to Content
API ReferenceGet Quote

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/quote

Authentication Required: Yes (API Key via X-API-Key header)


Request Parameters

Query Parameters

ParameterTypeRequiredDescriptionExample
sellTokenstringYesToken contract address to sell (EIP-55 checksummed)0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
buyTokenstringYesToken contract address to buy (EIP-55 checksummed)0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
sellAmountstringYesAmount in smallest units (wei for 18 decimals)1000000000000000000 (1 WETH)
userAddressstringYesUser’s wallet address (for gas estimation & tx building)0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb
chainIdnumberNoChain ID (default: 1 for Ethereum mainnet)1
slippageBpsnumberNoSlippage tolerance in basis points (default: 50)100 (1%)

Headers

HeaderRequiredDescriptionExample
X-API-KeyYesYour UNIKRON API keyuk_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 -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

FieldTypeDescription
okboolRequest success indicator (true on success)
dataobjectQuote data object (see below)
timestampnumberUnix timestamp in milliseconds

Quote Data Object

FieldTypeDescription
sourcestringWinning DEX aggregator (KyberSwap, 1inch, ParaSwap, Uniswap)
sellTokenstringToken being sold (checksummed address)
buyTokenstringToken being bought (checksummed address)
sellAmountstringInput amount in smallest units
buyAmountstringExpected output amount (before slippage)
minBuyAmountstringMinimum acceptable output (with 0.6% slippage tolerance)
estimatedGasnumberEstimated gas consumption in units
priceImpactnumberPrice impact percentage (0.12 = 0.12%)
dexRouteobjectDEX routing information
scoringobjectValue scoring metrics
alternativesarrayAlternative routes with lower prices
mevAnalysisobjectMEV threat analysis
mevProtectionobjectMEV protection details & transaction params

DEX Route Object

FieldTypeDescription
dexstringSelected DEX name
targetstring⚠️ Router address (approve tokens to this address)
patharrayToken swap path
datastringEncoded swap calldata (immutable, do not modify)

Scoring Object

FieldTypeDescription
netValueUsdnumberNet value after fees (USD)
gasCostUsdnumberEstimated gas cost (USD)

MEV Protection Object

FieldTypeDescription
providerstringMEV protection service (e.g., “MEV Blocker”)
transactionParamsobjectComplete EIP-1559 transaction ready for signing
providerMetadataobjectMEV provider configuration (required for order submission - see next table)

Transaction Parameters (Sign These)

FieldTypeDescription
tostringTarget contract address
datastringTransaction calldata
valuestringETH value (“0” for ERC-20 swaps)
gasLimitstringMaximum gas limit
maxFeePerGasstringMaximum fee per gas unit (wei)
maxPriorityFeePerGasstringPriority fee (always “0” for MEV protection)
noncenumberTransaction nonce
chainIdnumberNetwork chain ID (1 = Ethereum mainnet)
typenumberTransaction 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.

FieldTypeDescription
providerstringProvider identifier (“mev_blocker”)
tiernumberProtection tier (2 or 4)
mevBlockerMetadataobjectMEV Blocker specific configuration

MEV Blocker Metadata

FieldTypeDescription
endpointstringMEV Blocker RPC endpoint with query params
endpointTypestringEndpoint type (fast, noreverts, fullprivacy)
expectedRebatenumberExpected MEV rebate in USD
shareModestringSharing mode (shareAll, shareSafe, none)
revertProtectionbooleanWhether revert protection is enabled
useBoostbooleanWhether 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

HTTPError CodeReasonSolution
400INVALID_TOKEN_ADDRESSInvalid address format/checksumUse EIP-55 checksummed addresses
400NATIVE_ETH_NOT_SUPPORTEDUsed ETH instead of WETHUse WETH address instead
400INVALID_AMOUNTAmount is 0 or negativeProvide positive amount in wei
400USER_ADDRESS_REQUIREDMissing user parameterAdd user wallet address to request
401UNAUTHORIZEDInvalid/missing API keyCheck X-API-Key header
404INSUFFICIENT_LIQUIDITYNo route foundTry smaller amount or different pair
404TOKEN_NOT_SUPPORTEDToken not supportedCheck supported token list
429RATE_LIMIT_EXCEEDEDToo many requestsWait and retry with backoff
500INTERNAL_SERVER_ERRORServer errorRetry with exponential backoff
503SERVICE_UNAVAILABLEUpstream aggregator downRetry 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

See: Submit Order Endpoint

// 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`);


Need Help?

Last updated on