Currently, my strategy involves creating a Transaction object (e.g., TransferTransaction) that is configured to meet the necessary requirements, including specifying the required signatures. Next, I freeze the transaction and add any local signatures, and serialize it to allow users to add their own signatures and interrogate the transaction properties.
Once all signatures have been added to the transaction, I execute it. However, if the signatures are not added within the transactionValidDuration, the network returns TRANSACTION_EXPIRED
.
const transferTransaction = new TransferTransaction()
.addHbarTransfer(senderAccountId, new Hbar(1))
.addHbarTransfer(receiverAccountId, new Hbar(-1))
.setNodeAccountIds(nodeId);
//Freeze the transaction from further modifications
const transaction = await transferTransaction.freezeWith(client);
const signature1 = privateKeySigner1.signTransaction(transaction);
//Signer two signs the transaction with their private key
const signature2 = privateKeySigner2.signTransaction(transaction);
//Signer three signs the transaction with their private key
const signature3 = privateKeySigner3.signTransaction(transaction);
const signedTransaction = transaction.addSignature(publicKey1, signature1).addSignature(publicKey2, signature2).addSignature(publicKey3, signature3);
I am curious if there is an accepted pattern for gathering signatures that allows for a longer time frame than the default 180 seconds.
The validity of a transaction is limited to 180 seconds and cannot be extended beyond that. I know that collecting multiple signatures will require more than 180 seconds, which is why we have a scheduled transaction. A scheduled transaction allows you to submit a transaction to the network, and it will wait to be executed until it has all the required signatures. Currently, the maximum valid time for a scheduled transaction is 30 minutes. However, there is a proposal to extend the validity of scheduled transactions outlined in HIP-423, which you may want to review.
You can also take a look at the example code for scheduling transactions here: https://docs.hedera.com/hedera/tutorials/more-tutorials/schedule-your-first-transaction.