chunk-J3FJQ5OV.js•2.52 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunk7QVYU63Ejs = require('./chunk-7QVYU63E.js');
// src/api.ts
var TransactionHelperApi = class {
static {
_chunk7QVYU63Ejs.__name.call(void 0, this, "TransactionHelperApi");
}
/**
* Helper function to fetch transaction history using Helius API directly
* @param connection - Solana connection object containing the API key
* @param address - The address to get transaction history for
* @param options - Query parameters
* @returns Array of transaction data from Helius
*/
async getTransactionHistory(connection, address, options = {}) {
try {
const queryParams = {};
if (options.limit) {
queryParams.limit = options.limit.toString();
}
if (options.before) {
queryParams.before = options.before;
}
if (options.until) {
queryParams.until = options.until;
}
if (options.types && options.types.length > 0) {
queryParams.type = options.types.join(",");
}
if (options.minContextSlot) {
queryParams.minContextSlot = options.minContextSlot.toString();
}
const queryString = Object.entries(queryParams).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join("&");
const rpcUrl = connection.rpcEndpoint;
const apiKey = rpcUrl.split("api-key=")[1];
if (!apiKey) {
throw new Error("Missing Helius API key in connection endpoint");
}
const url = `https://api.helius.xyz/v0/addresses/${address}/transactions?api-key=${apiKey}${queryString ? `&${queryString}` : ""}`;
const response = await fetch(url);
if (!response.ok) {
if (response.status === 429) {
throw new Error("Helius API rate limit exceeded");
}
const errorText = await response.text();
throw new Error(`Helius API error: ${response.status} ${errorText}`);
}
const data = await response.json();
return data.map((tx) => ({
signature: tx.signature,
slot: tx.slot,
timestamp: tx.timestamp,
err: tx.err,
memo: tx.memo || null,
blockTime: tx.timestamp,
type: tx.type || "Unknown",
fee: tx.fee || 0,
status: tx.err ? "Failed" : "Success"
}));
} catch (error) {
console.error("Error in getTransactionHistory:", error);
throw error;
}
}
};
exports.TransactionHelperApi = TransactionHelperApi;
//# sourceMappingURL=chunk-J3FJQ5OV.js.map