forked from mediolano-app/mediolano-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-historical-events.js
More file actions
49 lines (39 loc) · 1.69 KB
/
test-historical-events.js
File metadata and controls
49 lines (39 loc) · 1.69 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
const { RpcProvider } = require("starknet");
async function main() {
const rpcUrl = "https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_10/tOTwt1ug3YNOsaPjinDvS";
const provider = new RpcProvider({ nodeUrl: rpcUrl });
const contractAddress = "0x05e73b7be06d82beeb390a0e0d655f2c9e7cf519658e04f05d9c690ccc41da03";
// Selectors
const selectors = [
"0x3e517dedbc7bae62d4ace7e3dfd33255c4a7fe7c1c6f53c725d52b45f9c5a00", // TokenMinted
"0x2f241bb3f752d1fb3ac68c703d92bb418a7a7c165f066fdb2d90094b5d95f0e", // CollectionCreated
"0x3ddaa3f2d17cc7984d82075aa171282e6fff4db61944bf218f60678f95e2567" // TokenTransferred
];
console.log("Testing fetch from block 1861690...\n");
try {
const response = await provider.getEvents({
address: contractAddress,
keys: [selectors], // OR filter: any of these selectors
from_block: { block_number: 1861690 },
chunk_size: 100 // Fetch a larger chunk to see count
});
console.log(`Events found: ${response.events.length}`);
console.log(`Has more: ${!!response.continuation_token}`);
if (response.continuation_token) {
console.log(`Continuation token: ${response.continuation_token}`);
}
// Count by type
const counts = {};
response.events.forEach(e => {
const key = e.keys[0];
counts[key] = (counts[key] || 0) + 1;
});
console.log("\nCounts by selector:");
Object.entries(counts).forEach(([key, count]) => {
console.log(`${key}: ${count}`);
});
} catch (error) {
console.error("ERROR:", error.message);
}
}
main();