1inch Integration
Access 1inch DEX aggregator through Axol for optimal swap routing across decentralized exchanges.
Endpoints
Get Swap Quote
POST /v1/integrations/dex/1inch/quote
Get the best swap rate and route without executing.
Request
{
"chain": "ethereum",
"from_token": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"to_token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"amount": "1000000000000000000",
"slippage": 0.5
}
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
chain | string | Yes | Target chain |
from_token | string | Yes | Source token address |
to_token | string | Yes | Destination token address |
amount | string | Yes | Amount in wei |
slippage | float | No | Slippage tolerance % (default 0.5) |
Response
{
"success": true,
"data": {
"from_token": {
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"symbol": "WETH",
"decimals": 18
},
"to_token": {
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"symbol": "USDC",
"decimals": 6
},
"from_amount": "1000000000000000000",
"to_amount": "3000000000",
"to_amount_min": "2985000000",
"estimated_gas": 250000,
"protocols": [
{
"name": "UNISWAP_V3",
"part": 80,
"from_token_address": "0xC02aaA39...",
"to_token_address": "0xA0b86991..."
},
{
"name": "CURVE",
"part": 20,
"from_token_address": "0xC02aaA39...",
"to_token_address": "0xA0b86991..."
}
],
"price_impact": 0.05
}
}
Execute Swap
POST /v1/integrations/dex/1inch/swap
Get swap transaction data for execution.
Request
{
"chain": "ethereum",
"from_token": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"to_token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"amount": "1000000000000000000",
"from_address": "0x123...",
"slippage": 0.5,
"disable_estimate": false
}
Additional Parameters
| Field | Type | Description |
|---|---|---|
from_address | string | Wallet address executing the swap |
disable_estimate | boolean | Skip gas estimation (default false) |
permit | string | Optional EIP-2612 permit signature |
Response
{
"success": true,
"data": {
"tx": {
"from": "0x123...",
"to": "0x1111111254EEB25477B68fb85Ed929f73A960582",
"data": "0x...",
"value": "0",
"gas": 250000,
"gasPrice": "25000000000"
},
"from_amount": "1000000000000000000",
"to_amount": "3000000000",
"to_amount_min": "2985000000"
}
}
Get Supported Tokens
GET /v1/integrations/dex/1inch/supported-tokens
Returns list of tokens supported for swapping.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
chain | string | Target chain (default: ethereum) |
Response
{
"success": true,
"data": {
"chain": "ethereum",
"tokens": [
{
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"symbol": "WETH",
"name": "Wrapped Ether",
"decimals": 18,
"logo_uri": "https://..."
},
{
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"symbol": "USDC",
"name": "USD Coin",
"decimals": 6,
"logo_uri": "https://..."
}
]
}
}
Supported Chains
| Chain | Chain ID | Status |
|---|---|---|
| ethereum | 1 | Production |
| polygon | 137 | Production |
| arbitrum | 42161 | Production |
| optimism | 10 | Production |
| base | 8453 | Production |
| avalanche | 43114 | Production |
Code Examples
Python - Swap Helper
import requests
from web3 import Web3
class OneInchClient:
def __init__(self, api_key: str):
self.api_key = api_key
self.base_url = "https://api.axol.io/api/v1/integrations/dex/1inch"
self.headers = {"X-API-Key": api_key}
def get_quote(
self,
chain: str,
from_token: str,
to_token: str,
amount: int,
slippage: float = 0.5
) -> dict:
"""Get swap quote."""
response = requests.post(
f"{self.base_url}/quote",
headers=self.headers,
json={
"chain": chain,
"from_token": from_token,
"to_token": to_token,
"amount": str(amount),
"slippage": slippage
}
)
return response.json()["data"]
def get_swap_data(
self,
chain: str,
from_token: str,
to_token: str,
amount: int,
from_address: str,
slippage: float = 0.5
) -> dict:
"""Get swap transaction data."""
response = requests.post(
f"{self.base_url}/swap",
headers=self.headers,
json={
"chain": chain,
"from_token": from_token,
"to_token": to_token,
"amount": str(amount),
"from_address": from_address,
"slippage": slippage
}
)
return response.json()["data"]
# Common token addresses
TOKENS = {
"WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"USDC": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"USDT": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
"DAI": "0x6B175474E89094C44Da98b954EescdeCB5BE7fae"
}
# Usage
client = OneInchClient(api_key="YOUR_KEY")
# Get quote for 1 ETH -> USDC
quote = client.get_quote(
chain="ethereum",
from_token=TOKENS["WETH"],
to_token=TOKENS["USDC"],
amount=Web3.to_wei(1, "ether")
)
print(f"1 WETH -> {int(quote['to_amount']) / 1e6:.2f} USDC")
print(f"Price impact: {quote['price_impact']:.2f}%")
print(f"Routes: {[p['name'] for p in quote['protocols']]}")
TypeScript - Swap Execution
import { ethers } from 'ethers';
interface SwapQuote {
from_amount: string;
to_amount: string;
to_amount_min: string;
protocols: Array<{ name: string; part: number }>;
price_impact: number;
}
interface SwapTx {
tx: {
from: string;
to: string;
data: string;
value: string;
gas: number;
gasPrice: string;
};
to_amount: string;
to_amount_min: string;
}
class SwapClient {
private apiKey: string;
private baseUrl = 'https://api.axol.io/api/v1/integrations/dex/1inch';
private wallet: ethers.Wallet;
constructor(apiKey: string, privateKey: string, provider: ethers.Provider) {
this.apiKey = apiKey;
this.wallet = new ethers.Wallet(privateKey, provider);
}
async getQuote(
chain: string,
fromToken: string,
toToken: string,
amount: bigint
): Promise<SwapQuote> {
const response = await fetch(`${this.baseUrl}/quote`, {
method: 'POST',
headers: {
'X-API-Key': this.apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({
chain,
from_token: fromToken,
to_token: toToken,
amount: amount.toString()
})
});
const data = await response.json();
return data.data;
}
async getSwapTx(
chain: string,
fromToken: string,
toToken: string,
amount: bigint,
slippage = 0.5
): Promise<SwapTx> {
const response = await fetch(`${this.baseUrl}/swap`, {
method: 'POST',
headers: {
'X-API-Key': this.apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({
chain,
from_token: fromToken,
to_token: toToken,
amount: amount.toString(),
from_address: this.wallet.address,
slippage
})
});
const data = await response.json();
return data.data;
}
async executeSwap(
chain: string,
fromToken: string,
toToken: string,
amount: bigint,
slippage = 0.5
): Promise<ethers.TransactionReceipt> {
// Get swap data
const swapData = await this.getSwapTx(chain, fromToken, toToken, amount, slippage);
// Execute transaction
const tx = await this.wallet.sendTransaction({
to: swapData.tx.to,
data: swapData.tx.data,
value: swapData.tx.value,
gasLimit: swapData.tx.gas
});
return await tx.wait();
}
}
// Usage
const provider = new ethers.JsonRpcProvider('...');
const client = new SwapClient(
process.env.AXOL_API_KEY!,
process.env.PRIVATE_KEY!,
provider
);
// Get quote
const quote = await client.getQuote(
'ethereum',
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
ethers.parseEther('1')
);
console.log(`Expected: ${Number(quote.to_amount) / 1e6} USDC`);
// Execute (only if quote is acceptable)
if (quote.price_impact < 1) {
const receipt = await client.executeSwap(
'ethereum',
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
ethers.parseEther('1')
);
console.log(`Swap executed: ${receipt.hash}`);
}
Best Practices
1. Always Get Quote First
Check the quote before executing to avoid surprises:
quote = client.get_quote(...)
# Check price impact
if quote["price_impact"] > 1.0:
print("Warning: High price impact!")
return
# Check minimum received
min_received = int(quote["to_amount_min"]) / 1e6 # USDC
if min_received < expected_min:
print("Quote below expectations")
return
2. Set Appropriate Slippage
| Use Case | Recommended Slippage |
|---|---|
| Stablecoin pairs | 0.1-0.3% |
| Major tokens | 0.5% |
| Volatile tokens | 1-3% |
| Low liquidity | 3-5% |
3. Approve Tokens First
Ensure token approval before swapping:
# Check and approve if needed
allowance = token_contract.functions.allowance(
wallet_address,
ONEINCH_ROUTER
).call()
if allowance < amount:
approve_tx = token_contract.functions.approve(
ONEINCH_ROUTER,
2**256 - 1 # Max approval
).build_transaction({...})
# Sign and send approval
4. Handle Partial Fills
Large swaps may be partially filled:
receipt = await execute_swap(...)
# Check actual amount received from events
See Also
- DeFiLlama Integration - TVL and yields
- Gas API - Gas estimation
- Error Handling - Error codes