Cosign aggregate transactions pending to be signed.
This guide assumes that you have received an aggregate transaction. You can follow the guide creating an escrow contract to announce an aggregate transaction.
1. First, check if your account has incoming aggregate transactions that have not been signed.
Use the TransactionHttp
repository to search all the incoming aggregate transactions pending to be signed by your account.
// replace with account address
const rawAddress = 'TAXQUT-QQNS6J-EJG7PL-C6FRVJ-2USS44-GLMVUL-PGQ';
const address = Address.createFromRawAddress(rawAddress);
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();
const searchCriteria = {group: TransactionGroup.Partial, address, pageNumber: 1, pageSize: 100};
transactionHttp
.search(searchCriteria)
.subscribe((page) => console.log(page.data),
(err) => console.error(err));
// replace with account address
const rawAddress = 'TAXQUT-QQNS6J-EJG7PL-C6FRVJ-2USS44-GLMVUL-PGQ';
const address = symbol_sdk_1.Address.createFromRawAddress(rawAddress);
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();
const searchCriteria = { group: symbol_sdk_1.TransactionGroup.Partial, address, pageNumber: 1, pageSize: 100 };
transactionHttp
.search(searchCriteria)
.subscribe((page) => console.log(page.data), (err) => console.error(err));
Copy and save the transaction hash you want to cosign with your account.
const cosignAggregateBondedTransaction = (transaction: AggregateTransaction, account: Account): CosignatureSignedTransaction => {
const cosignatureTransaction = CosignatureTransaction.create(transaction);
return account.signCosignatureTransaction(cosignatureTransaction);
};
const cosignAggregateBondedTransaction = (transaction, account) => {
const cosignatureTransaction = symbol_sdk_1.CosignatureTransaction.create(transaction);
return account.signCosignatureTransaction(cosignatureTransaction);
};
3. Define the transaction hash to cosign and the signer account. If you want to cosign a transaction involving a multisig account, you should be using the cosignatory account instead.
// replace with network type
const networkType = NetworkType.TEST_NET;
// replace with private key
const privateKey = '0000000000000000000000000000000000000000000000000000000000000000';
const account = Account.createFromPrivateKey(privateKey, networkType);
// replace with node endpoint
// replace with transaction hash to cosign
const transactionHash = '0000000000000000000000000000000000000000000000000000000000000000';
// replace with network type
const networkType = symbol_sdk_1.NetworkType.TEST_NET;
// replace with private key
const privateKey = '0000000000000000000000000000000000000000000000000000000000000000';
const account = symbol_sdk_1.Account.createFromPrivateKey(privateKey, networkType);
// replace with node endpoint
// replace with transaction hash to cosign
const transactionHash = '0000000000000000000000000000000000000000000000000000000000000000';
4. Retrieve the complete transaction object from the node using the TransactionHttp
repository.
At this point, you might want to do some extra checks, like verifying the contents of the transaction.
If everything looks ok, cosign the transaction with the signer account.
Finally, announce the cosignature to network with transactionHttp.announceAggregateBondedCosignature
.
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();
const accountHttp = repositoryFactory.createAccountRepository();
transactionHttp
.getTransaction(transactionHash, TransactionGroup.Partial)
.pipe(
map((transaction) => cosignAggregateBondedTransaction(transaction as AggregateTransaction, account)),
mergeMap((cosignatureSignedTransaction) =>
transactionHttp.announceAggregateBondedCosignature(cosignatureSignedTransaction)),
)
.subscribe((announcedTransaction) => console.log(announcedTransaction),
(err) => console.error(err));
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();
const accountHttp = repositoryFactory.createAccountRepository();
transactionHttp
.getTransaction(transactionHash, symbol_sdk_1.TransactionGroup.Partial)
.pipe(operators_1.map((transaction) => cosignAggregateBondedTransaction(transaction, account)), operators_1.mergeMap((cosignatureSignedTransaction) => transactionHttp.announceAggregateBondedCosignature(cosignatureSignedTransaction)))
.subscribe((announcedTransaction) => console.log(announcedTransaction), (err) => console.error(err));
Once all the participants cosign the transaction, the transaction will be included in a block.
symbol-cli transaction search --address TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I --group Partial
symbol-cli transaction cosign --hash A6A374E66B32A3D5133018EFA9CD6E3169C8EEA339F7CCBE29C47D07086E068C
Did you find what you were looking for? Give us your feedback.