-
Notifications
You must be signed in to change notification settings - Fork 0
/
opensea.js
72 lines (58 loc) · 1.94 KB
/
opensea.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
const OpenSea = require('opensea-js'); //import the OpenSea library
//replace this placeholder with your own OpenSea API key
const OPENSEA_API_KEY = 'YOUR_OPENSEA_API_KEY';
//create a new OpenSea client
const opensea = new OpenSea(OPENSEA_API_KEY);
//function to get the collection stats from OpenSea
async function getCollectionStats() {
//fetch the collection stats from OpenSea
const collection = await opensea.getCollection({
owner: 'opensea',
slug: 'crypto-kitties',
});
//extract the desired stats from the collection object
const stats = {
name: collection.name,
totalSupply: collection.total_supply,
circulatingSupply: collection.circulating_supply,
numSales: collection.num_sales,
};
//return the extracted stats
return stats;
}
//function to get the listing updates from OpenSea
async function getListingUpdates() {
//fetch the listing updates from OpenSea
const updates = await opensea.getUpdates({
owner: 'opensea',
slug: 'crypto-kitties',
event_type: 'listing_created',
});
//return the listing updates
return updates;
}
//function to get the sales updates from OpenSea
async function getSalesUpdates() {
//fetch the sales updates from OpenSea
const updates = await opensea.getUpdates({
owner: 'opensea',
slug: 'crypto-kitties',
event_type: 'sale_created',
});
//return the sales updates
return updates;
}
//main function that gets the collection stats, listing updates, and sales updates
async function main() {
//get the collection stats
const collectionStats = await getCollectionStats();
//get the listing updates
const listingUpdates = await getListingUpdates();
//get the sales updates
const salesUpdates = await getSalesUpdates();
console.log(collectionStats);
console.log(listingUpdates);
console.log(salesUpdates);
}
//run the main function
main();