-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherc721Snapshot.js
More file actions
55 lines (47 loc) · 1.23 KB
/
erc721Snapshot.js
File metadata and controls
55 lines (47 loc) · 1.23 KB
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
const { createPublicClient, http } = require("viem");
const { mainnet } = require("viem/chains");
const client = createPublicClient({
chain: mainnet,
transport: http("https://api.mainnet.abs.xyz")
});
const contractAddress = "0x67266b806a2987ef6dfaf6355ccd62c29978dbf9";
const abi = [ // Basic ERC721 ABI
{
name: "ownerOf",
type: "function",
stateMutability: "view",
inputs: [{ name: "tokenId", type: "uint256" }],
outputs: [{ name: "", type: "address" }]
},
{
name: "totalSupply",
type: "function",
stateMutability: "view",
inputs: [],
outputs: [{ name: "", type: "uint256" }]
}
];
async function getSnapshot() {
const holders = {};
// Get total supply
const totalSupply = await client.readContract({
address: contractAddress,
abi,
functionName: "totalSupply"
});
for (let i = 0; i < Number(totalSupply); i++) {
try {
const owner = await client.readContract({
address: contractAddress,
abi,
functionName: "ownerOf",
args: [BigInt(i)]
});
holders[owner] = (holders[owner] || 0) + 1;
} catch (e) {
console.log(`Token ${i} may not exist`);
}
}
console.log("Snapshot complete:", holders);
}
getSnapshot();