The HeliusService provides methods for fetching and processing Solana transaction history using the Helius RPC endpoint. It handles transaction type detection, status formatting, and fee calculation.
Overview
Helius is a high-performance RPC provider for Solana that offers enhanced APIs for querying blockchain data. The HeliusService wraps the Solana Web3.js connection to provide a simplified interface for transaction history retrieval.
HeliusService
fetchAllTransactions
Fetch all transactions for a given Solana wallet address.
async fetchAllTransactions(address: string): Promise<TransactionHistoryResponse>
Solana wallet address (base58 encoded public key)
TransactionHistoryResponse
Response containing transaction historyArray of transaction logs with details
TransactionLog Structure
Individual transaction log entryTransaction signature (unique identifier)
Unix timestamp in seconds (block time)
Human-readable transaction type (e.g., ‘System Transfer’, ‘Token Transfer’, ‘Jupiter Swap’, ‘Deriverse’)
Transaction fee in lamports
Behavior
- Fetches last 50 transaction signatures for the address
- Retrieves full transaction details for each signature
- Supports versioned transactions (maxSupportedTransactionVersion: 0)
- Uses ‘confirmed’ commitment level for reliability
- Skips transactions that fail to fetch (logs warning)
- Detects transaction type from program IDs in logs
Transaction Type Detection
The service automatically detects transaction types based on program IDs:
| Program ID | Detected Type |
|---|
11111111111111111111111111111111 | System Transfer |
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA | Token Transfer |
| Contains ‘JUP’ | Jupiter Swap |
Matches PROGRAM_ID constant | Deriverse |
| Unknown | Transaction |
Format Unix timestamp to localized string.
static formatTime(timestamp: number): string
Unix timestamp in seconds
Formatted date string (localized)
Example Usage
Basic Transaction Fetching
import { HeliusService } from '@/services/HeliusService';
const heliusService = new HeliusService();
const walletAddress = '7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU';
try {
const response = await heliusService.fetchAllTransactions(walletAddress);
console.log(`Found ${response.transactions.length} transactions`);
// Process each transaction
response.transactions.forEach(tx => {
const time = HeliusService.formatTime(tx.time);
console.log(`[${tx.status}] ${tx.type} - ${tx.signature.slice(0, 8)}...`);
console.log(` Time: ${time}`);
console.log(` Fee: ${tx.fee / 1e9} SOL`);
});
} catch (error) {
console.error('Failed to fetch transactions:', error);
}
Filtering Deriverse Transactions
const response = await heliusService.fetchAllTransactions(walletAddress);
const deriverseTransactions = response.transactions.filter(
tx => tx.type === 'Deriverse' && tx.status === 'Confirmed'
);
console.log(`Found ${deriverseTransactions.length} Deriverse transactions`);
// Calculate total fees
const totalFees = deriverseTransactions.reduce(
(sum, tx) => sum + tx.fee,
0
);
console.log(`Total fees: ${totalFees / 1e9} SOL`);
Displaying Transaction History
import { HeliusService } from '@/services/HeliusService';
function TransactionHistory({ walletAddress }: { walletAddress: string }) {
const [transactions, setTransactions] = useState<TransactionLog[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchTxs = async () => {
try {
const heliusService = new HeliusService();
const response = await heliusService.fetchAllTransactions(walletAddress);
setTransactions(response.transactions);
} catch (error) {
console.error('Error fetching transactions:', error);
} finally {
setLoading(false);
}
};
fetchTxs();
}, [walletAddress]);
if (loading) return <div>Loading transactions...</div>;
return (
<div>
<h2>Transaction History</h2>
{transactions.map(tx => (
<div key={tx.signature}>
<span className={tx.status === 'Confirmed' ? 'success' : 'error'}>
{tx.status}
</span>
<span>{tx.type}</span>
<span>{HeliusService.formatTime(tx.time)}</span>
<a href={`https://solscan.io/tx/${tx.signature}`} target="_blank">
View on Solscan
</a>
</div>
))}
</div>
);
}
Error Handling
The service includes comprehensive error handling:
try {
const response = await heliusService.fetchAllTransactions(invalidAddress);
} catch (error) {
// Error messages are user-friendly
// "Failed to fetch transactions. Please check the address and try again."
console.error(error.message);
}
Configuration
The service uses the RPC connection from ../lib/utils.getRpcConnection(), which should be configured with your Helius API key:
// lib/utils.ts
export function getRpcConnection(): Connection {
const endpoint = process.env.NEXT_PUBLIC_RPC_HTTP || 'https://api.mainnet-beta.solana.com';
return new Connection(endpoint, 'confirmed');
}
- Limit: Fetches maximum 50 transactions per call
- Commitment: Uses ‘confirmed’ commitment (good balance of speed and reliability)
- Versioning: Supports v0 transactions (required for modern Solana programs)
- Error Recovery: Individual transaction fetch failures don’t block the entire operation