-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignatures.js
50 lines (41 loc) · 1.65 KB
/
signatures.js
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
const { Connection, PublicKey } = require('@solana/web3.js');
require('dotenv').config();
const SOLANA_CONNECTION = process.env.SOLANA_CONNECTION;
const connection = new Connection(SOLANA_CONNECTION, 'confirmed');
const address = process.argv[2];
const limit = process.argv[3];
const pubkey = new PublicKey(address)
const getSignatures = async (pkey) => {
signatureBlock = await connection.getSignaturesForAddress(pkey);
// console.log(JSON.stringify(signatures));
return signatureBlock // console.log(JSON.stringify(signatures));
};
const getSignaturesBefore = async (pkey, params) => {
signatureBlock = await connection.getSignaturesForAddress(pkey, params);
// console.log(JSON.stringify(signatures));
return signatureBlock // console.log(JSON.stringify(signatures));
};
let signatures = []
let remainder = 0
let finished
const getSignaturesWithLimit = async () => {
const signaturesBlock = await getSignatures(pubkey)
signaturesBlock.forEach(signature => {
signatures.push(signature);
});
remainder = signaturesBlock.length % 1000
while (remainder === 0 && signatures.length < limit) {
const earliest = signatures[signatures.length - 1].signature
// console.log(earliest)
const params = {before: earliest}
// console.log(params)
const signaturesBlock = await getSignaturesBefore(pubkey, params)
// console.log(signaturesBlock)
signaturesBlock.forEach(signature => {
signatures.push(signature);
});
remainder = signaturesBlock.length % 1000
}
console.log(JSON.stringify(signatures))
};
getSignaturesWithLimit();