-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshot.js
64 lines (58 loc) · 2.14 KB
/
snapshot.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
require('dotenv').config();
const { Connection, PublicKey } = require('@solana/web3.js');
const { TOKEN_PROGRAM_ID } = require('@solana/spl-token');
const { writeFileSync } = require('fs');
// Replace this with your custom RPC URL from QuickNode or other provider
const rpcUrl = process.env.RPC_URL;
const connection = new Connection(rpcUrl, 'confirmed');
const mintAddress = process.env.TOKEN_MINT_ADDRESS;
// Define your token's mint address
const tokenMintAddress = new PublicKey(mintAddress);
async function getTokenAccountsByMint(mintAddress) {
const accounts = await connection.getParsedProgramAccounts(
TOKEN_PROGRAM_ID,
{
filters: [
{
dataSize: 165, // size of a token account
},
{
memcmp: {
offset: 0, // location of mint address in token account data
bytes: mintAddress.toBase58(),
},
},
],
}
);
// Filter accounts to show only those with more than 1000 tokens
// Filter accounts to show only those with more than 1000 tokens
return accounts
.map(account => {
const owner = account.account.data.parsed.info.owner;
const ownerAddress = owner instanceof PublicKey ? owner.toBase58() : owner;
return {
ownerAddress,
publicKey: account.pubkey.toBase58(),
amount: parseFloat(account.account.data.parsed.info.tokenAmount.uiAmountString),
airdrop: parseFloat(account.account.data.parsed.info.tokenAmount.uiAmountString) * 0.1
};
})
.filter(account => account.amount > 100);
}
async function snapshotTokenHolders() {
try {
const tokenAccounts = await getTokenAccountsByMint(tokenMintAddress);
console.log('Token Holders Snapshot:', tokenAccounts);
writeFileSync('tokenHoldersSnapshot.json', JSON.stringify(tokenAccounts, null, 2));
console.log('Snapshot written to tokenHoldersSnapshot.json');
} catch (error) {
if (error.message.includes('422 Unprocessable Entity')) {
console.error(error.message);
console.error('You may need to use a different RPC node or handle the error case differently.');
} else {
console.error('Error taking snapshot:', error);
}
}
}
snapshotTokenHolders();