swapExactMASForTokens method
swapExactMASForTokens swaps exact amount of input MAS coins to a specified output token
Implementation
Future<(String, bool)> swapExactMASForTokens(BigInt amountIn, BigInt amountOut, List<dynamic> binSteps,
List<dynamic> tokenPath, String toAddress, int deadline) async {
final deadline2 = BigInt.from(DateTime.timestamp().millisecondsSinceEpoch + deadline);
final storageCost = 0.1;
final params = Args();
params.addU256(amountOut);
params.addArray(binSteps, ArrayTypes.U64);
params.addArray(tokenPath, ArrayTypes.STRING);
params.addString(toAddress);
params.addU64(deadline2);
params.addU64(fromMAS(storageCost)); //storage cost 0.1 MAS
const targetFunction = "swapExactMASForTokens";
final functionParameters = params.serialise();
final maximumGas = toMAS(BigInt.from(GasLimit.MAX_GAS_CALL.value));
final smartContracAddress = grpc.isBuildnet ? BuildnetConstants.routerAddress : MainnetConstants.routerAddress;
final coins = toMAS(amountIn) + storageCost;
return await grpc.scCall(
account: grpc.account,
fee: minimumFee,
coins: coins,
maximumGas: maximumGas,
smartContracAddress: smartContracAddress,
functionName: targetFunction,
functionParameters: functionParameters,
);
}