transferWithOptIn method

Future<String> transferWithOptIn(
  1. AptosAccount sender,
  2. String creator,
  3. String collectionName,
  4. String tokenName,
  5. BigInt propertyVersion,
  6. String receiver,
  7. BigInt amount, {
  8. BigInt? maxGasAmount,
  9. BigInt? gasUnitPrice,
  10. BigInt? expireTimestamp,
})

Directly transfer token from sender to a receiver. The receiver should have opted in to direct transfer.

Implementation

Future<String> transferWithOptIn(
  AptosAccount sender,
  String creator,
  String collectionName,
  String tokenName,
  BigInt propertyVersion,
  String receiver,
  BigInt amount, {
  BigInt? maxGasAmount,
  BigInt? gasUnitPrice,
  BigInt? expireTimestamp
}) {
  // compile script to invoke public transfer function
  final payload = TransactionPayloadScript(
    Script(
      HexString(TOKEN_TRANSFER_OPT_IN).toUint8Array(),
      [],
      [
        TransactionArgumentAddress(AccountAddress.fromHex(creator)),
        TransactionArgumentU8Vector(Uint8List.fromList(utf8.encode(collectionName))),
        TransactionArgumentU8Vector(Uint8List.fromList(utf8.encode(tokenName))),
        TransactionArgumentU64(propertyVersion),
        TransactionArgumentAddress(AccountAddress.fromHex(receiver)),
        TransactionArgumentU64(amount),
      ],
    ),
  );

  return aptosClient.generateSignSubmitTransaction(
    sender,
    payload,
    maxGasAmount: maxGasAmount,
    gasUnitPrice: gasUnitPrice,
    expireTimestamp: expireTimestamp
  );
}