-
Notifications
You must be signed in to change notification settings - Fork 44
/
getSnapshot.js
80 lines (69 loc) · 2.08 KB
/
getSnapshot.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const anchor = require("@project-serum/anchor");
const fs = require("fs");
const web3 = require("@solana/web3.js");
const connection = new anchor.web3.Connection(
"https://solana-api.projectserum.com"
);
if (process.argv.length < 4) {
console.log("Usage: node " + process.argv[1] + " inputFile outputFile");
process.exit(1);
}
var inputFile = process.argv[2];
var outputFile = process.argv[3];
console.log(inputFile);
// @ts-ignore
var list = [];
const TOKEN_PUBKEY = new web3.PublicKey(
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
);
const getNftOwner = async (address) => {
try {
let filter = {
memcmp: {
offset: 0,
bytes: address,
},
};
let filter2 = {
dataSize: 165,
};
let getFilter = [filter, filter2];
let programAccountsConfig = { filters: getFilter, encoding: "jsonParsed" };
let _listOfTokens = await connection.getParsedProgramAccounts(
TOKEN_PUBKEY,
programAccountsConfig
);
let res;
for (let i = 0; i < _listOfTokens.length; i++) {
if (
_listOfTokens[i]["account"]["data"]["parsed"]["info"]["tokenAmount"][
"amount"
] == 1
) {
res = _listOfTokens[i]["account"]["data"]["parsed"]["info"]["owner"];
console.log(_listOfTokens[i]["account"]["data"]["parsed"]["info"]["owner"]);
console.log(
_listOfTokens[i]["account"]["data"]["parsed"]["info"]["tokenAmount"][
"amount"
]);
}
}
return res;
} catch (e) {
console.log(e);
}
};
const owners = async () => {
let newList = [];
var data = fs.readFileSync(inputFile, "utf8", function (err, data) {
if (err) throw err;
console.log("OK: " + inputFile);
});
data = data.replace(/[^a-zA-Z0-9]/g, " ").trim().replace(/[\s,]+/g,',').split(",")
console.log(data)
for (let i = 0; i <= data.length-1; i++) {
newList.push({ mint: data[i], holder: await getNftOwner(data[i]) });
}
fs.writeFileSync(outputFile, JSON.stringify(newList));
};
owners();