From e13efa0883c06e4349f7e162bde55f088ea99f70 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Wed, 13 Apr 2022 12:54:46 +0800 Subject: [PATCH] fix: do not modify transaction during simulation --- web3.js/src/connection.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index 56b407c234..d1dd883874 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -3878,7 +3878,14 @@ export class Connection { ): Promise> { let transaction; if (transactionOrMessage instanceof Transaction) { - transaction = transactionOrMessage; + let originalTx: Transaction = transactionOrMessage; + transaction = new Transaction({ + recentBlockhash: originalTx.recentBlockhash, + nonceInfo: originalTx.nonceInfo, + feePayer: originalTx.feePayer, + signatures: [...originalTx.signatures], + }); + transaction.instructions = transactionOrMessage.instructions; } else { transaction = Transaction.populate(transactionOrMessage); } @@ -3888,11 +3895,7 @@ export class Connection { } else { let disableCache = this._disableBlockhashCaching; for (;;) { - if (!transaction.recentBlockhash) { - transaction.recentBlockhash = await this._recentBlockhash( - disableCache, - ); - } + transaction.recentBlockhash = await this._recentBlockhash(disableCache); if (!signers) break;