makeTransfer method
Implementation
Future<Transaction?> makeTransfer(MakeTransferOptions options) async {
var appConfig = _ensureAppConfig();
AppConfigMint? mint = _getAppMint(appConfig, options.mint);
var commitment = options.commitment ?? Commitment.confirmed;
var destination = options.destination;
var senderCreate = options.senderCreate ?? false;
_validateDestination(appConfig, destination);
List<String>? accounts = await getTokenAccounts(GetTokenAccountsOptions(
account: options.destination,
mint: mint.publicKey,
));
if (!senderCreate && (accounts == null || accounts.isEmpty)) {
throw Exception("Destination account does not exist");
}
PrepareTransactionResponse blockhash = await _getBlockhash();
SignedTx tx = await generateMakeTransferTransaction(GenerateMakeTransferOptions(
addMemo: mint.addMemo,
amount: options.amount,
blockhash: blockhash.blockhash,
destination: options.destination,
index: sdkConfig.index,
lastValidBlockHeight: blockhash.lastValidBlockHeight,
mintDecimals: mint.decimals,
mintFeePayer: mint.feePayer,
mintPublicKey: mint.publicKey,
owner: options.owner,
senderCreate: options.senderCreate,
type: options.type ?? TransactionType.none,
));
final request = MakeTransferRequest(
commitment: commitment,
environment: sdkConfig.environment,
index: sdkConfig.index,
lastValidBlockHeight: blockhash.lastValidBlockHeight,
mint: mint.publicKey,
referenceId: options.referenceId,
referenceType: options.referenceType,
tx: tx.encode(),
);
return transactionApi.makeTransfer(request);
}