Generate calldata to swap on 1inch Router
Supported on: Ethereum Base BNB Chain Sonic Unichain Robinhood Arbitrum Avalanche ZKsync Gnosis Optimism Polygon Linea
Parameters
chain
* number path src
* string query dst
* string query amount
* string query from
* string queryThe address that calls the 1inch contract
origin
* string queryAn EOA address that initiate the transaction
protocols
string queryAll supported liquidity sources by default
fee
number queryPartner fee in percent. min: 0; max: 3 Should be the same for /quote and /swap
gasPrice
string queryNetwork price per gas in wei. By default fast network gas price
complexityLevel
number query parts
number query mainRouteParts
number query gasLimit
number query includeTokensInfo
boolean queryReturn fromToken and toToken info in response
includeProtocols
boolean queryReturn used swap protocols in response
includeGas
boolean queryReturn approximated gas in response
connectorTokens
string query excludedProtocols
string queryexcluded supported liquidity sources
slippage
number querySlippage tolerance in percent. Min: 0; Max: 50.
Use either slippage or minReturn, not both.
Advantages of slippage:
- minReturn is calculated relative to the actual rate
- For tokens with fee-on-transfer, re-estimation occurs and slippage is applied to the actual amount
- Allows path re-routing if initial estimation fails
Disadvantages of slippage:
- The /swap result needs verification - check how much slippage the user agrees to accept
Example: slippage=1 means accepting up to 1% less than the expected amount.
minReturn
string queryMinimum amount of destination token that must be received, in the smallest unit (considering decimals).
Use either minReturn or slippage, not both.
Advantages of minReturn:
- Result guaranteed to not be lower than this amount
Disadvantages of minReturn:
- If rate changes between /quote and /swap requests, you'll get an error
- Must be calculated manually relative to quote.dstAmount minus desired slippage percentage
- Must be manually selected for fee-on-transfer tokens
- Path won't be re-estimated if estimation fails
- Requires precise calculation and understanding of the value being set
Example: For a token with 18 decimals, minReturn=1000000000000000000 requires at least 1 token.
permit
string queryhttps://eips.ethereum.org/EIPS/eip-2612
receiver
string queryThis address will receive funds after the swap. By default same address as "from" param
referrer
string queryThe address that will receive the partner fee specified by the "fee" param. Required when "fee" is set.
allowPartialFill
boolean queryBy default set to false
compatibility
boolean queryAllows to swap tokens with internal transfer fee
disableEstimate
boolean queryEnable this flag to disable onchain simulation
usePatching
boolean queryEnable this flag if you patch input amount on your smart contract
usePermit2
boolean queryEnable this flag in case you did an approval to permit2 smart contract
forceApprove
boolean queryWhen enabled, the approval check during simulation will be skipped
createAccessList
boolean queryWhen enabled, generates and returns an EIP-2930 access list in the response
Request Body
This request doesn’t have any request body.
JavaScript
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const axios = require('axios');
async function httpCall() {
const url = 'https://api.1inch.com/swap/v6.1/{chain}/swap';
const config = {
headers: {
Authorization: `Bearer ${API_KEY}`,
},
params: {
src: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
dst: '0x111111111117dc0aa78b770fa6a738034120c302',
amount: '10000000000000000',
slippage: 1,
minReturn: '1000000000000000000',
},
paramsSerializer: {
indexes: null,
},
};
const body = {};
try {
const response = await axios.get(url, body, config);
console.log(response.data);
} catch (error) {
console.error(error);
}
}
Returns
200
400
403
500
srcToken
any Source token info
allOf[0]
TokenInfo object address
* string symbol
* string name
* string decimals
* number logoURI
* string domainVersion
string eip2612
boolean isFoT
boolean tags
array items
string dstToken
any Destination token info
allOf[0]
TokenInfo object address
* string symbol
* string name
* string decimals
* number logoURI
* string domainVersion
string eip2612
boolean isFoT
boolean tags
array items
string dstAmount
* string Expected amount of destination token
protocols
array Selected protocols in a path
items
TokenSwaps object token
* string Source token address for the hops
hops
* array Swap hops from source token
items
TokenHop object part
* number The distribution percent from source token coming to destination token on this hop
dst
* string Destination token address
fromTokenId
* number Source token index in the path
toTokenId
* number Destination token index in the path
protocols
* array The token split among different liquidity sources
items
SelectedLiquiditySource object name
* string The liquidity source id
part
* number The distribution percent from total amount coming to specified destination token
tx
* any Transaction object
allOf[0]
TransactionData object from
* string to
* string data
* string value
* string gasPrice
* string gas
* number gasUsed
number Simulated gas used (from `eth_createAccessList`). Set only when access lists are enabled for the chain and the returned list is non-empty.
accessList
array EIP-2930 access list. When the client sets createAccessList=true, this field and `gasUsed` are always present; if no slots are needed, `accessList` may be an empty array and `gasUsed` is set to the transaction gas limit.
items
AccessSlotsDto object address
* string Contract address
storageKeys
* array Storage keys accessed by the contract
items
string JSON
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{
"srcToken": {
"address": "0x111111111117dc0aa78b770fa6a738034120c302",
"symbol": "1INCH",
"name": "1INCH Token",
"decimals": 18,
"logoURI": "https://tokens.1inch.io/0x111111111117dc0aa78b770fa6a738034120c302.png",
"domainVersion": "string",
"eip2612": true,
"isFoT": false,
"tags": ["tokens"]
},
"dstToken": {
"address": "0x111111111117dc0aa78b770fa6a738034120c302",
"symbol": "1INCH",
"name": "1INCH Token",
"decimals": 18,
"logoURI": "https://tokens.1inch.io/0x111111111117dc0aa78b770fa6a738034120c302.png",
"domainVersion": "string",
"eip2612": true,
"isFoT": false,
"tags": ["tokens"]
},
"dstAmount": "62131879850006790961",
"protocols": [
{
"token": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"hops": [
{
"part": 100,
"dst": "0x111111111117dc0aa78b770fa6a738034120c302",
"fromTokenId": 0,
"toTokenId": 1,
"protocols": [
{
"name": "UNISWAP_V3",
"part": 100
}
]
}
]
}
],
"tx": {
"from": "0x1111111111111111111111111111111111111111",
"to": "0x1111111254eeb25477b68fb85ed929f73a960582",
"data": "0x0502b1c50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000003556e53186804ca3e0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000180000000000000003b6d034026aad2da94c59524ac0d93f6d6cbf9071d7086f2",
"value": "10000000000000000",
"gasPrice": "6994090150",
"gas": 121363,
"gasUsed": 95000,
"accessList": [
{
"address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"storageKeys": [
"0x0000000000000000000000000000000000000000000000000000000000000000"
]
}
]
}
}