If your requirement is to get the confirmed transaction, then the ideal way is to wait until the transaction is confirmed and then fetch the transaction by Id.
async waitForConfirmation(txId: string): Promise<A_PendingTransactionResponse> {
const status = await this.client.status().do();
let lastRound = status[“last-round”];
while (true) {
const pendingInfo = await this.client.pendingTransactionInformation(txId).do();
if (pendingInfo[“confirmed-round”] !== null && pendingInfo[“confirmed-round”] > 0) {
return pendingInfo as A_PendingTransactionResponse;
}
lastRound++;
await this.client.statusAfterBlock(lastRound).do();
}
};
I’ve boiled your code down to the simplest thing that works for us:
//
// Computes a transaction id from a transaction in a block.
//
function computeTransactionId(gh: Buffer, gen: string, stib: any) {
const t = stib.txn as algosdk.EncodedTransaction;
// Manually add gh/gen to construct a correct transaction object
t.gh = gh;
t.gen = gen;
const stxn = {
txn: algosdk.Transaction.from_obj_for_encoding(t),
} as algosdk.SignedTransaction;
if ("sig" in stib) {
stxn.sig = stib.sig;
}
if ("lsig" in stib) {
stxn.lsig = stib.lsig;
}
if ("msig" in stib) {
stxn.msig = stib.msig;
}
if ("sgnr" in stib) {
stxn.sgnr = stib.sgnr;
}
return stxn.txn.txID();
}