getQuote method
getQuote endpoint of DNL API should be used only to display outcomes of the trades when the address of the user is unknown (e.g. to let the user see prices of cross-chain trades before he connects the wallet to the Dapp). Whenever an address is known, make sure to call getOrderCreationTransaction directly.
srcChainId
Specifies the identifier in which the order will be placed.
srcChainTokenIn
Sets the input token (the user is willing to give) to the token address on the target chain.
srcChainTokenInAmount
Specifies the desired input amount: since the USDC token contract uses 18 decimals (the number of digits that come after the decimal place when displaying token values on-screen), the simple math: 100*10^18 leads to 100000000000000000000 as the value representing 100 USDC tokens.
dstChainId
Specified the network chain ID as the destination chain where an order should be fulfilled.
dstChainTokenOut
Sets the output token (the user is willing to take).
prependOperatingExpense
Default - true. Asks the API to add the approximate amount of operating expenses to the amount of input token before making a quote.
affiliateFeePercent
Default - 0.1. Asks the order to accrue the given share of input amount, which would be paid after an order gets fulfilled and unlocked.
Implementation
Future<Route> getQuote({
required int srcChainId,
required String srcChainTokenIn,
required String srcChainTokenInAmount,
required int dstChainId,
required String dstChainTokenOut,
bool? prependOperatingExpense,
num? affiliateFeePercent,
}) async {
try {
var uri = Uri.parse(
"${entrypoint.uri}/v1.0/dln/order/quote?srcChainId=$srcChainId&srcChainTokenIn=$srcChainTokenIn&srcChainTokenInAmount=$srcChainTokenInAmount&dstChainId=$dstChainId&dstChainTokenOut=$dstChainTokenOut&prependOperatingExpenses=${prependOperatingExpense ?? true}&affiliateFeePercent=${affiliateFeePercent ?? 0.1}");
var response = await http.get(uri);
if (response.statusCode != 200) {
throw json.decode(response.body);
}
var jsonDecode = json.decode(response.body);
return Route.fromJson(jsonDecode);
} catch (e) {
throw Exception(e.toString());
}
}