Skip to content

Transaction Aggregate complete

Wei Hau Lim edited this page May 13, 2022 · 5 revisions

Aggregate complete transaction

Aggregate Complete transaction is a method to execute multiple transactions at once. To be valid, all transactions included in aggregate complete should be signed by aggregate complete transaction owner. If valid, it will be included in a block.

  • Following parameters required:
    • Inner transactions - List of transactions signed by aggregate complete owner. Other aggregate transactions are not allowed as inner transactions.
import 'package:xpx_chain_sdk/xpx_sdk.dart';

const baseUrl = 'http://bctestnet3.brimstone.xpxsirius.io:3000';

/// Creating a client instance
/// xpx_chain_sdk uses the Dart's native HttpClient.
/// Depending on the platform, you may want to use either
/// the one which comes from dart:io or the BrowserClient
/// example:
/// 1- import 'package:http/browser_client.dart';
/// 2- var client = newClient(config,  BrowserClient());
final client = SiriusClient.fromUrl(baseUrl, null);

/// Simple Account API AnnounceTransaction
void main() async {
  final networkType = await client.networkType;
  final generationHash = await client.generationHash;

  final deadline = Deadline(hours: 1);

  /// Create an Account from a given Private key. (signer)
  final account = await Account.fromPrivateKey(
      '5D39DFFB41BB92C5932C29BAB4E1E5AC2C1901784BF008DC937A8A460B925331',
      networkType);

  /// Create an Address from a given Public key.
  final recipient = await Address.fromPublicKey(
      '68f50e10e5b8be2b7e9ddb687a667d6e94dd55fe02b4aed8195f51f9a242558c',
      networkType);

  /// Create a transfer type transaction as the first inner transaction
  final transaction1 = TransferTransaction.create(
      // The maximum amount of time to include the transaction in the blockchain.
      deadline,
      // The Address of the recipient account.
      recipient,
      // The List of mosaic to be sent.
      [xpx(52)],
      // The transaction message of 1024 characters.
      PlainMessage(payload: 'From ProximaX Dart SDK UNO'),
      networkType);

  /// Create another transfer type transaction as the second inner transaction
  final transaction2 = TransferTransaction.create(
      // The maximum amount of time to include the transaction in the blockchain.
      deadline,
      // The Address of the recipient account.
      recipient,
      // The List of mosaic to be sent.
      [xpxRelative(15)],
      // The transaction message of 1024 characters.
      PlainMessage(payload: 'From ProximaX Dart SDK DOS'),
      networkType);

  transaction1.toAggregate = account.publicAccount;
  transaction2.toAggregate = account.publicAccount;

  // Create Aggregate complete transaction.
  final aggregateTransaction = AggregateTransaction.complete(
      deadline, [transaction1, transaction2], networkType);

  final signedTransaction =
      await account.signTransaction(aggregateTransaction, generationHash);

  try {
    final restTx = await client.transaction.announce(signedTransaction);
    print(restTx);
    print('Hash: ${signedTransaction.hash}');
    print('Signer: ${account.publicAccount.publicKey}');
  } on Exception catch (e) {
    print('Exception when calling Transaction->Announce: $e\n');
  }
}