Skip to main content

Swap Quotes

Get swap quotes from multiple DEX aggregators in one request.

Try it Live

Open in Swagger UI โ†’ to test these endpoints interactively.

Endpointsโ€‹

EndpointDescriptionPrice
GET /api/swap/quoteGet swap quote$0.002
GET /api/swap/routesCompare routes$0.005
GET /api/swap/tokensSupported tokensFREE

GET /api/swap/quoteโ€‹

Get the best swap quote across multiple DEX aggregators.

Requestโ€‹

curl "https://api.web3identity.com/api/swap/quote?\
fromToken=ETH&\
toToken=USDC&\
amount=1&\
chainId=1"

Query Parametersโ€‹

ParamTypeRequiredDescription
fromTokenstringYesSource token (symbol or address)
toTokenstringYesDestination token
amountstringYesAmount to swap (in token units)
chainIdnumberNoChain ID (default: 1)
slippagenumberNoMax slippage % (default: 0.5)
senderstringNoSender address (for gas estimate)

Responseโ€‹

{
"fromToken": {
"symbol": "ETH",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"decimals": 18
},
"toToken": {
"symbol": "USDC",
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"decimals": 6
},
"fromAmount": "1000000000000000000",
"toAmount": "3245670000",
"toAmountFormatted": "3245.67",
"rate": 3245.67,
"priceImpact": "0.02%",
"route": {
"source": "1inch",
"path": ["WETH", "USDC"],
"pools": ["Uniswap V3 0.05%"]
},
"gas": {
"estimate": 150000,
"priceGwei": 25,
"costUSD": 12.50
},
"validUntil": "2026-02-08T04:35:00Z"
}

SDKโ€‹

const quote = await client.getSwapQuote({
fromToken: 'ETH',
toToken: 'USDC',
amount: '1',
chainId: 1
});

console.log(`1 ETH = ${quote.toAmountFormatted} USDC`);
console.log(`Price impact: ${quote.priceImpact}`);

JavaScriptโ€‹

const BASE_URL = 'https://api.web3identity.com';

async function getSwapQuote({ fromToken, toToken, amount, chainId = 1 }) {
const params = new URLSearchParams({
fromToken,
toToken,
amount: amount.toString(),
chainId: chainId.toString()
});

const response = await fetch(`${BASE_URL}/api/swap/quote?${params}`);

if (!response.ok) {
throw new Error(`Quote failed: ${response.status}`);
}

return response.json();
}

// Example: Get ETH โ†’ USDC quote
const quote = await getSwapQuote({
fromToken: 'ETH',
toToken: 'USDC',
amount: 1
});

console.log(`Rate: 1 ETH = $${quote.rate.toFixed(2)}`);
console.log(`You receive: ${quote.toAmountFormatted} USDC`);
console.log(`Gas cost: ~$${quote.gas.costUSD.toFixed(2)}`);

Pythonโ€‹

import requests

BASE_URL = "https://api.web3identity.com"

def get_swap_quote(from_token: str, to_token: str, amount: float, chain_id: int = 1) -> dict:
response = requests.get(
f"{BASE_URL}/api/swap/quote",
params={
"fromToken": from_token,
"toToken": to_token,
"amount": str(amount),
"chainId": chain_id
}
)
response.raise_for_status()
return response.json()

# Get quote
quote = get_swap_quote("ETH", "USDC", 1.0)
print(f"1 ETH โ†’ {quote['toAmountFormatted']} USDC")
print(f"Via: {quote['route']['source']}")

cURLโ€‹

# Get ETH to USDC quote with formatting
curl -s "https://api.web3identity.com/api/swap/quote?\
fromToken=ETH&\
toToken=USDC&\
amount=1&\
chainId=1" | jq '{
from: "\(.fromToken.symbol)",
to: "\(.toToken.symbol)",
rate: .rate,
receive: .toAmountFormatted,
gasCost: "$\(.gas.costUSD)",
source: .route.source
}'

GET /api/swap/routesโ€‹

Compare quotes from multiple aggregators.

Requestโ€‹

curl "https://api.web3identity.com/api/swap/routes?\
fromToken=ETH&\
toToken=USDC&\
amount=10&\
chainId=1"

Responseโ€‹

{
"fromToken": "ETH",
"toToken": "USDC",
"amount": "10",
"routes": [
{
"source": "1inch",
"toAmount": "32456.70",
"rate": 3245.67,
"gas": 150000,
"priceImpact": "0.05%"
},
{
"source": "paraswap",
"toAmount": "32445.20",
"rate": 3244.52,
"gas": 165000,
"priceImpact": "0.06%"
},
{
"source": "0x",
"toAmount": "32440.00",
"rate": 3244.00,
"gas": 145000,
"priceImpact": "0.05%"
}
],
"best": {
"byAmount": "1inch",
"byGas": "0x"
}
}

Use Case: Best Executionโ€‹

const routes = await fetch(
'https://api.web3identity.com/api/swap/routes?fromToken=ETH&toToken=USDC&amount=10'
).then(r => r.json());

// Find best by net output (amount - gas cost)
const bestRoute = routes.routes.reduce((best, route) => {
const netValue = parseFloat(route.toAmount) - (route.gas * 0.00003 * 3200); // rough ETH gas cost
return netValue > best.netValue ? { ...route, netValue } : best;
}, { netValue: 0 });

console.log(`Best route: ${bestRoute.source}`);

GET /api/swap/tokensโ€‹

Get list of supported tokens for swaps.

Requestโ€‹

curl "https://api.web3identity.com/api/swap/tokens?chainId=1"

Responseโ€‹

{
"chainId": 1,
"tokens": [
{
"symbol": "ETH",
"name": "Ethereum",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"decimals": 18,
"logoURI": "https://..."
},
{
"symbol": "USDC",
"name": "USD Coin",
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"decimals": 6,
"logoURI": "https://..."
}
],
"count": 5000
}

Supported Chainsโ€‹

ChainIDStatus
Ethereum1โœ…
Arbitrum42161โœ…
Optimism10โœ…
Base8453โœ…
Polygon137โœ…

Quote Sourcesโ€‹

We aggregate from:

SourceSpecialty
1inchBest overall routing
ParaSwapMEV protection
0xProfessional traders
UniswapDirect pool access
CowswapGasless trades

Error Handlingโ€‹

CodeHTTPDescription
INSUFFICIENT_LIQUIDITY400Not enough liquidity for amount
TOKEN_NOT_FOUND404Token not supported
INVALID_CHAIN400Chain ID not supported
QUOTE_EXPIRED410Quote no longer valid

Error Responseโ€‹

{
"error": true,
"code": "INSUFFICIENT_LIQUIDITY",
"message": "Insufficient liquidity for 1000 ETH โ†’ USDC swap"
}

Best Practicesโ€‹

1. Always Check Price Impactโ€‹

const quote = await getSwapQuote({ fromToken: 'ETH', toToken: 'USDC', amount: 100 });

if (parseFloat(quote.priceImpact) > 1) {
console.warn('High price impact! Consider smaller trade.');
}

2. Use Fresh Quotesโ€‹

// Quotes expire quickly - fetch just before executing
const quote = await getSwapQuote(params);

if (new Date(quote.validUntil) < new Date()) {
// Refetch
quote = await getSwapQuote(params);
}

3. Include Gas in Calculationsโ€‹

const netOutput = parseFloat(quote.toAmountFormatted) - quote.gas.costUSD;
console.log(`Net output after gas: $${netOutput.toFixed(2)}`);


Try It Nowโ€‹

๐Ÿ’ฑ Open Swagger UI โ†’