The Enhanced Transactions API transforms complex Solana transactions into human-readable data. Instead of dealing with raw instruction data and account lists, you get structured information about:
What happened in the transaction (transfers, swaps, NFT activities)
Runtime Type Filtering:Type filtering happens at runtime, meaning the API searches through transactions sequentially until it finds at least 50 matching items. If the API cannot find any transactions matching your filter within the search period, it will return an error with instructions to continue searching.
When using type filters, you may encounter a situation where no matching transactions are found within the current search window. In this case, the API returns an error response like:
Report incorrect code
Copy
Ask AI
{ "error": "Failed to find events within the search period. To continue search, query the API again with the `before-signature` parameter set to 2UKbsu95YzxGjUGYRg2znozmmVADVgmnhHqzDxq8Xfb3V5bf2NHUkaXGPrUpQnRFVHVKbawdQXtm4xJt9njMDHvg."}
To continue the search, you need to use the signature provided in the error message with the appropriate parameter (before-signature for descending, after-signature for ascending) in your next request. Here’s how to handle this:
Report incorrect code
Copy
Ask AI
const fetchFilteredTransactions = async (sortOrder = 'desc') => { const walletAddress = "M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K"; const transactionType = "NFT_SALE"; let continuationSignature = null; let allFilteredTransactions = []; let maxRetries = 10; // Prevent infinite loops let retryCount = 0; // Determine which parameter to use based on sort order const continuationParam = sortOrder === 'asc' ? 'after-signature' : 'before-signature'; while (retryCount < maxRetries) { // Build URL with optional continuation parameter let url = `https://api-mainnet.helius-rpc.com/v0/addresses/${walletAddress}/transactions?api-key=YOUR_API_KEY&type=${transactionType}&sort-order=${sortOrder}`; if (continuationSignature) { url += `&${continuationParam}=${continuationSignature}`; } try { const response = await fetch(url); const data = await response.json(); // Check if we received an error about search period if (data.error && data.error.includes("Failed to find events within the search period")) { // Extract the signature from the error message const signatureMatch = data.error.match(/parameter set to ([A-Za-z0-9]+)/); if (signatureMatch && signatureMatch[1]) { console.log(`No results in this period. Continuing search from: ${signatureMatch[1]}`); continuationSignature = signatureMatch[1]; retryCount++; continue; // Continue searching with new signature } else { console.log("No more transactions to search"); break; } } // Check if we received transactions if (Array.isArray(data) && data.length > 0) { console.log(`Found ${data.length} ${transactionType} transactions`); allFilteredTransactions = [...allFilteredTransactions, ...data]; // Set continuation signature for next page continuationSignature = data[data.length - 1].signature; retryCount = 0; // Reset retry count since we found results } else { console.log("No more transactions found"); break; } } catch (error) { console.error("Error fetching transactions:", error); break; } } console.log(`Total ${transactionType} transactions found: ${allFilteredTransactions.length}`); return allFilteredTransactions;};// Usage examples:// Descending order (newest first) - uses 'before-signature' parameterfetchFilteredTransactions('desc');// Ascending order (oldest first) - uses 'after-signature' parameterfetchFilteredTransactions('asc');
Key Points:
The API searches through up to 50 transactions at a time when using type filters
If no matches are found, use the signature from the error message to continue searching
Use before-signature parameter when searching in descending order (default, newest first)
Use after-signature parameter when searching in ascending order (oldest first) - this is required for chronological searches
Implement a maximum retry limit to prevent infinite loops
This behavior is expected and allows you to search through an address’s entire history for specific transaction types
For frequently asked questions about Enhanced Transactions including usage, authentication, rate limits, and troubleshooting, visit our comprehensive Enhanced Transactions FAQ.