-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopensea-listener.mjs
More file actions
30 lines (26 loc) · 1.1 KB
/
Copy pathopensea-listener.mjs
File metadata and controls
30 lines (26 loc) · 1.1 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
import { Network, OpenSeaStreamClient } from '@opensea/stream-js';
import ws from 'ws';
import config from './config.js';
const client = new OpenSeaStreamClient({
token: config.OPENSEA.API_KEY,
network: config.OPENSEA.NETWORK,
connectOptions: { transport: ws },
onError(error) {
if (error.message === 'Connection disconnected') {
client.connect();
}
},
});
function handler(type, data) {
console.log(type, data);
}
function listenToCollectionEvents(collection) {
client.onItemListed(collection, (data) => handler('onItemListed', data));
client.onItemSold(collection, (data) => handler('onItemSold', data));
client.onItemTransferred(collection, (data) => handler('onItemTransferred', data));
client.onItemMetadataUpdated(collection, (data) => handler('onItemMetadataUpdated', data));
client.onItemCancelled(collection, (data) => handler('onItemCancelled', data));
client.onItemReceivedOffer(collection, (data) => handler('onItemReceivedOffer', data));
client.onItemReceivedBid(collection, (data) => handler('onItemReceivedBid', data));
}
listenToCollectionEvents('kitaroworldofficial');