From d6c5ce08bb0475e3b1769fcdc7375cbeaf3212d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salle=20Helev=C3=A4?= <52321471+ilmari-h@users.noreply.github.com> Date: Fri, 20 Dec 2024 21:30:49 +0100 Subject: [PATCH] Add method for parse transactions endpoint (#154) --- src/Helius.ts | 31 +++++++++++++++++++++++++++++++ src/types/types.ts | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/src/Helius.ts b/src/Helius.ts index 9f3609a..7de6947 100644 --- a/src/Helius.ts +++ b/src/Helius.ts @@ -13,6 +13,8 @@ import { RevokeCollectionAuthorityRequest, HeliusCluster, HeliusEndpoints, + ParseTransactionsRequest, + ParseTransactionsResponse, } from './types'; import axios, { type AxiosError } from 'axios'; @@ -659,4 +661,33 @@ export class Helius { ); return collectionMetadataAccount; } + + /** + * Parse transactions. + * @param {ParseTransactionsRequest} params - The request parameters + * @returns {Promise} - Array of parsed transactions + * @throws {Error} If there was an error calling the endpoint or too many transactions to parse + */ + async parseTransactions( + params: ParseTransactionsRequest + ): Promise { + if (params.transactions.length > 100) { + throw new Error('The maximum number of transactions to parse is 100'); + } + + const response = await axios.post( + this.getApiEndpoint('/v0/transactions'), + { + ...params, + }, + { + headers: { 'Content-Type': 'application/json' }, + } + ); + if (response.data.error) { + throw new Error(`RPC error: ${JSON.stringify(response.data.error)}`); + } + + return response.data as ParseTransactionsResponse; + } } diff --git a/src/types/types.ts b/src/types/types.ts index d556554..24171b8 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -386,3 +386,9 @@ export interface SmartTransactionOptions extends SendOptions { export interface HeliusSendOptions extends SolanaWebJsSendOptions { validatorAcls?: string[]; } + +export interface ParseTransactionsRequest { + transactions: string[]; +} + +export type ParseTransactionsResponse = EnrichedTransaction[];