[SOLVED] 1inch plugin: get quote by the token out amount

for 1inch plugin, is there any way to get quote by token out amount? for example, users want to swap bnb to usdt, but he just want to swap to 2000 usdt, we need to show how many bnb in the token in to get 2000 usdt.

const quote = await dex.quote({
        chain: 'bsc', // The blockchain you want to use (eth/bsc/polygon)
        fromTokenAddress: currentTrade.from.address, // The token you want to swap
        toTokenAddress: currentTrade.to.address, // The token you want to receive
        amount: amount,
    })

You could get the token price before doing that swap and compute an approximate value for amount.

ah, I got it. Do we have function to get token price or we just call the quote api for amount = 1 (for example) then get the token price?

You can call the quote only. Because the price is really depends on amount you want to swap

1 Like