txnhelper.service.ts•1.61 kB
import { Tool } from "@goat-sdk/core";
import { SolanaWalletClient } from "@goat-sdk/wallet-solana";
import { TransactionHelperApi, TransactionData, TransactionHistoryOptions } from "./api";
import { GetTransactionHistoryParameters } from "./parameters";
import { TransactionHelperOptions } from "./txnhelper.plugin";
export class TransactionHelperService {
private api: TransactionHelperApi;
constructor(api: TransactionHelperApi, private readonly options?: TransactionHelperOptions) {
this.api = api;
}
@Tool({
name: "txnhelper_get_transaction_history",
description: "Get transaction history for a Solana wallet address or token account using Helius API",
})
async getTransactionHistory(walletClient: SolanaWalletClient, params: GetTransactionHistoryParameters): Promise<TransactionData[]> {
try {
// Get connection from the wallet client
const connection = walletClient.getConnection();
// Convert parameters to the format expected by the API
const options: TransactionHistoryOptions = {
limit: params.limit,
before: params.before,
until: params.until,
types: params.types,
minContextSlot: params.minContextSlot
};
// Call the API method
return this.api.getTransactionHistory(connection, params.address, options);
} catch (error) {
console.error('Error in getTransactionHistory service:', error);
throw error;
}
}
}