-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolana.js
62 lines (57 loc) · 1.71 KB
/
solana.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
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @author JeffVader
*/
const axios = require('axios');
const path = require('path');
const fs = require('fs');
const holders = [];
function writeToFileSync(filepath, args) {
const flag = 'w';
const fd = fs.openSync(filepath, flag);
fs.writeSync(fd, args);
fs.closeSync(fd);
}
function start(mint) {
axios.post('http://api.mainnet-beta.solana.com', {
jsonrpc: '2.0',
id: 1,
method: 'getProgramAccounts',
params: [
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
{
encoding: 'jsonParsed',
filters: [
{
dataSize: 165,
},
{
memcmp: {
offset: 0,
bytes: mint,
},
},
],
},
],
}).then((response) => {
let total = 0;
response.data.result.forEach((holder) => {
if (Number(holder.account.data.parsed.info.tokenAmount.amount) > 0) {
total += Number(holder.account.data.parsed.info.tokenAmount.amount / (10 ** holder.account.data.parsed.info.tokenAmount.decimals));
holders.push(
{
address: holder.pubkey,
owner: holder.account.data.parsed.info.owner,
amount: Number(holder.account.data.parsed.info.tokenAmount.amount),
decimals: holder.account.data.parsed.info.tokenAmount.decimals,
},
);
}
});
const homeDirPath = path.join(__dirname, './export/');
const filepath = `${homeDirPath}solanalist.json`;
console.log(`Done Solana - ${holders.length} records found. Exported at ${filepath}. Total Flux-SOL: ${total.toLocaleString()} (${total})`);
writeToFileSync(filepath, JSON.stringify(holders, null, 2));
});
}
module.exports = { start };