-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
50 lines (40 loc) · 1.9 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Connection, PublicKey, ConfirmedSignatureInfo } from '@solana/web3.js';
import fs from 'fs';
// const
const RPC_ENDPOINT = 'https://api.mainnet-beta.solana.com';
const VOTE_ACCOUNT_ADDRESS = 'YOUR_VOTE_KEY';
const BATCH_SIZE = 1000;
const RATE_LIMIT_DELAY = 1000;
const connection = new Connection(RPC_ENDPOINT, 'confirmed');
async function fetchTransactionHistory(): Promise<void> {
const address = new PublicKey(VOTE_ACCOUNT_ADDRESS);
let allSignatures: ConfirmedSignatureInfo[] = [];
let beforeSignature: string | undefined = undefined;
try {
// all signatures in batches
while (true) {
const signatures = await connection.getConfirmedSignaturesForAddress2(address, {
before: beforeSignature,
limit: BATCH_SIZE,
}, 'confirmed');
if (signatures.length === 0) {
break;
}
allSignatures.push(...signatures);
beforeSignature = signatures[signatures.length - 1].signature;
console.log(`Fetched ${allSignatures.length} signatures so far`);
// safe to file after batch size
fs.writeFileSync('transactions_progress.json', JSON.stringify(allSignatures, null, 2));
console.log(`progress saved: ${allSignatures.length} signatures so far`);
// respect the rate limits
await new Promise(resolve => setTimeout(resolve, RATE_LIMIT_DELAY));
}
console.log(`total signatures fetched: ${allSignatures.length}`);
// final data after fetching all available transactions
fs.writeFileSync('transactions_final.json', JSON.stringify(allSignatures, null, 2));
console.log('Final transaction history saved to transactions_final.json');
} catch (error) {
console.error('Error fetching transaction history:', error);
}
}
fetchTransactionHistory().catch(console.error);