Signing announced aggregate bonded transactions

This guide will show you how to cosign aggregate bonded transactions that require your account’s cosignature.

Prerequisites

Getting into some code

You have announced an aggregate bonded transaction, but all required cosigners have not signed it yet.

  1. Create a function to cosign any aggregate bonded transaction.
const cosignAggregateBondedTransaction = (transaction: AggregateTransaction, account: Account): CosignatureSignedTransaction => {
    const cosignatureTransaction = CosignatureTransaction.create(transaction);
    return account.signCosignatureTransaction(cosignatureTransaction);
};
const cosignAggregateBondedTransaction = (transaction, account) => {
    const cosignatureTransaction = CosignatureTransaction.create(transaction);
    return account.signCosignatureTransaction(cosignatureTransaction);
};
  1. Fetch all aggregate bonded transactions pending to be signed by your account.

Note

To fetch aggregate bonded transactions that must be signed by multisig cosignatories, refer to the multisig public key instead. See how to get multisig accounts where an account is cosignatory.

  1. For each transaction, check if you have not already signed it. Cosign each pending transaction using the previously created function.
  2. Announce CosignatureSignedTransaction to the network using the TransactionHttp repository.
const privateKey = process.env.PRIVATE_KEY as string;
const account = Account.createFromPrivateKey(privateKey, NetworkType.MIJIN_TEST);

const nodeUrl = 'http://localhost:3000';
const accountHttp = new AccountHttp(nodeUrl);
const transactionHttp = new TransactionHttp(nodeUrl);

accountHttp
    .aggregateBondedTransactions(account.publicAccount)
    .pipe(
        mergeMap((_) => _),
        filter((_) => !_.signedByAccount(account.publicAccount)),
        map(transaction => cosignAggregateBondedTransaction(transaction, account)),
        mergeMap(cosignatureSignedTransaction => transactionHttp.announceAggregateBondedCosignature(cosignatureSignedTransaction))
    )
    .subscribe(announcedTransaction => console.log(announcedTransaction),
        err => console.error(err));
const privateKey = process.env.PRIVATE_KEY;
const account = Account.createFromPrivateKey(privateKey, NetworkType.MIJIN_TEST);

const nodeUrl = 'http://localhost:3000';
const accountHttp = new AccountHttp(nodeUrl);
const transactionHttp = new TransactionHttp(nodeUrl);

accountHttp
    .aggregateBondedTransactions(account.publicAccount)
    .pipe(
        mergeMap((_) => _),
        filter((_) => !_.signedByAccount(account.publicAccount)),
        map(transaction => cosignAggregateBondedTransaction(transaction, account)),
        mergeMap(cosignatureSignedTransaction => transactionHttp.announceAggregateBondedCosignature(cosignatureSignedTransaction))
    )
    .subscribe(announcedTransaction => console.log(announcedTransaction),
        err => console.error(err));
nem2-cli transaction cosign --hash A6A374E66B32A3D5133018EFA9CD6E3169C8EEA339F7CCBE29C47D07086E068C