createTransferTransaction method
Future<AptosRawTransaction>
createTransferTransaction({
- required AptosAddress sender,
- required AptosTransferParams transferParams,
- AptosApiBuildTransactionParams? params,
Creates a raw transaction for transferring Aptos tokens from the sender
to the specified transferParams
.
sender
: The address initiating the transaction.transferParams
: The parameters defining the transfer, such as the amount and destination.params
(optional): Custom transaction parameters like gas fees, expiration time, etc.
Throws an exception if the destination account is inactive and allowCreate
is set to false
.
Implementation
Future<AptosRawTransaction> createTransferTransaction({
required AptosAddress sender,
required AptosTransferParams transferParams,
AptosApiBuildTransactionParams? params,
}) async {
final isActive = await accountIsActive(transferParams.destination);
if (!transferParams.allowCreate && !isActive) {
throw DartAptosPluginException(
"Account is not active.",
details: {"address": transferParams.destination.toString()},
);
}
final entryFunction = isActive
? AptosHelper.createCoinTransferEntry(transferParams)
: AptosHelper.createAccountTransferEntry(transferParams);
final transactionPayload =
AptosTransactionPayloadEntryFunction(entryFunction: entryFunction);
return buildTransaction(
sender: sender,
transactionPayload: transactionPayload,
params: params,
);
}