Exact out
Last updated
Last updated
The goal of using "Exact Out" is to use "outAmount" to get desired "inAmount" on the frontend and receive the exact outAmount needed.
In the following, it will use to calculate the required inAmount
based on a target outAmount
, then construct a swap
transaction to complete an on-chain swap.
reverseQuote
✅ Description
Call the reverseQuote
API to return the actual input token amount required based on the desired output token and amount. Please refer it to get more info.
📍 Endpoint
📥 Parameters description:
inTokenAddress
Address of the input token (token to be swapped into on the frontend, same as outTokenAddress
in /swap
endpoint)
outTokenAddress
Address of the output token (token the user wants to receive, same as inTokenAddress
in /swap
endpoint)
amountDecimals
Amount of output token with decimals (e.g., 10 USDT should be written as 10000000
)
gasPriceDecimals
slippage
Set acceptable slippage by inputting a percentage value within the range of 0.05 to 50.
e.g. input "1" refer to "1%"
The default value of slippage is 1 (1%)
Example:
Response snippet:
Response params description:
inAmount
Desired output token amount (equal to the input parameter amountDecimals
)
outAmount
Estimated output amount (for reference only)
reverseAmount
Actual amount of input tokens required (used as amountDecimals
in /swap
endpoint)
/swap
endpoint to complete swaps✅ Description
Use the response from reverseQuote
endpoint to call the /swap
endpoint, generate the transaction data, and complete the on-chain trade.
📍Endpoint
📥 Parameters description:
inTokenAddress
Address of the input token (The outTokenAddress
from reverseQuote
)
outTokenAddress
Address of the output token (The inTokenAddress
from reverseQuote
)
account
Receiving address (can be a third-party address)
sender
Address used to initiate the transaction (user address)
amountDecimals
Input amount (The reverseAmount
from reverseQuote
)
gasPriceDecimals
slippage
Set acceptable slippage by inputting a percentage value within the range of 0.05 to 50.
e.g. input "1" refer to "1%"
The default value of slippage is 1 (1%)
outAmountDecimals
Target exact-out output amount (The inAmount
from reverseQuote
)
Example:
Response snippet:
Call reverseQuote
with the target outAmount
to calculate the required inAmount
;
Use reverseAmount
and inAmount
to construct the swap
endpoint request;
Call swap
, retrieve the transaction data, and execute the on-chain trade.
You can obtain the latest gasPriceDecimals
from:
Use the price_impact
from the reverseQuote
response to evaluate the output price quote if reasonable, such as set a threshold of price impact to avoid large losses;
All amount fields must be adjusted based on the token’s decimals
(e.g., USDT uses 6, ETH uses 18).
gas price with decimals (obtain via /gasPrice
)
gas price with decimals (obtain via /gasPrice
)
Reach out us in if you'd like help wrapping this into a script (Python, JS, etc.) or building a front-end widget.