Skip to content

Commit

Permalink
Add method for parse transactions endpoint (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmari-h authored Dec 20, 2024
1 parent c8da9c9 commit d6c5ce0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Helius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
RevokeCollectionAuthorityRequest,
HeliusCluster,
HeliusEndpoints,
ParseTransactionsRequest,
ParseTransactionsResponse,
} from './types';

import axios, { type AxiosError } from 'axios';
Expand Down Expand Up @@ -659,4 +661,33 @@ export class Helius {
);
return collectionMetadataAccount;
}

/**
* Parse transactions.
* @param {ParseTransactionsRequest} params - The request parameters
* @returns {Promise<ParseTransactionsResponse>} - 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<ParseTransactionsResponse> {
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;
}
}
6 changes: 6 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];

0 comments on commit d6c5ce0

Please sign in to comment.