From 0b93de9bd5449ba5ece47e16741f39fd43c80d3d Mon Sep 17 00:00:00 2001 From: Brennan Gebotys Date: Mon, 25 Apr 2022 09:46:33 -0400 Subject: [PATCH] feat: implement getTransactions (#23633) implement getTransactions which retrieves multiple transaction responses in a single RPC call Co-authored-by: obiwan --- web3.js/src/connection.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index 31036f023a4d2f..c21e032ce5d532 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -3404,6 +3404,34 @@ export class Connection { return res; } + /** + * Fetch transaction details for a batch of confirmed transactions. + * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}. + */ + async getTransactions( + signatures: TransactionSignature[], + commitment?: Finality, + ): Promise<(TransactionResponse | null)[]> { + const batch = signatures.map(signature => { + const args = this._buildArgsAtLeastConfirmed([signature], commitment); + return { + methodName: 'getTransaction', + args, + }; + }); + + const unsafeRes = await this._rpcBatchRequest(batch); + const res = unsafeRes.map((unsafeRes: any) => { + const res = create(unsafeRes, GetTransactionRpcResult); + if ('error' in res) { + throw new Error('failed to get transactions: ' + res.error.message); + } + return res.result; + }); + + return res; + } + /** * Fetch a list of Transactions and transaction statuses from the cluster * for a confirmed block.