Setting toAmount
If you want to buy something worth a certain amount, the best method is to overestimate by more than the expected slippage. We have a method on the SDK to estimate the required fromAmount
you need to get a toAmount
on the destination chain. It uses coingecko prices to approximate a number.
Get a fromAmount
based on fromToken
, toToken
and toAmount
.
Example usage:
const ETH = squid.getTokenData(
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"1"
);
const USDC = squid.getTokenData(
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"1"
);
const usdcToEth = await squid.getFromAmount({
fromToken: USDC,
toAmount: "1",
toToken: ETH
}); // expected: ~1600
const ethToUsdc = await squid.getFromAmount({
fromToken: ETH,
toAmount: "200",
toToken: USDC
}); // expected: ~0.12...
// you can also specify slippage percentage (default is 1.5%)
const usdcToEth3 = await squid.getFromAmount({
fromToken: USDC,
toAmount: "1",
toToken: ETH,
slippagePercentage: 3
}); // expected: ~1648
Last updated