directTransferToken method

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

Directly transfer the specified amount of tokens from account to receiver using a single multi signature transaction. And return the hash of the transaction submitted to the API.

Implementation

Future<String> directTransferToken(
  AptosAccount sender,
  AptosAccount receiver,
  String creator,
  String collectionName,
  String name,
  int amount,
  {int? propertyVersion,
  BigInt? maxGasAmount,
  BigInt? gasUnitPrice,
  BigInt? expireTimestamp}
) async {
  final payload = transactionBuilder.buildTransactionPayload(
    "0x3::token::direct_transfer_script",
    [],
    [creator, collectionName, name, propertyVersion, amount],
  );

  final rawTxn = await aptosClient.generateRawTransaction(
    sender.address,
    payload,
    maxGasAmount: maxGasAmount,
    gasUnitPrice: gasUnitPrice,
    expireTimestamp: expireTimestamp
  );
  final multiAgentTxn = MultiAgentRawTransaction(rawTxn, [
    AccountAddress.fromHex(receiver.address),
  ]);

  final senderSignature = Ed25519Signature(
    sender.signBuffer(TransactionBuilder.getSigningMessage(multiAgentTxn)).toUint8Array(),
  );

  final senderAuthenticator = AccountAuthenticatorEd25519(
    Ed25519PublicKey(Uint8List.fromList(sender.signingKey.publicKey.bytes)),
    senderSignature,
  );

  final receiverSignature = Ed25519Signature(
    receiver.signBuffer(TransactionBuilder.getSigningMessage(multiAgentTxn)).toUint8Array(),
  );

  final receiverAuthenticator = AccountAuthenticatorEd25519(
    Ed25519PublicKey(Uint8List.fromList(receiver.signingKey.publicKey.bytes)),
    receiverSignature,
  );

  final multiAgentAuthenticator = TransactionAuthenticatorMultiAgent(
    senderAuthenticator,
    [AccountAddress.fromHex(receiver.address)], // Secondary signer addresses
    [receiverAuthenticator], // Secondary signer authenticators
  );

  final bcsTxn = bcsToBytes(SignedTransaction(rawTxn, multiAgentAuthenticator));

  final transactionRes = await aptosClient.submitSignedBCSTransaction(bcsTxn);

  return transactionRes["hash"];
}