-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
39 lines (31 loc) · 956 Bytes
/
index.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
const openseaKey = ""
const {OpenSeaStreamClient, EventType} = require('@opensea/stream-js');
const {WebSocket} = require('ws')
const web3 = require('web3')
const client = new OpenSeaStreamClient({
token: openseaKey,
connectOptions: {
transport: WebSocket,
},
});
const args = process.argv.slice(2);
const slug = args[0];
function handleList(event) {
console.log('\x1b[36m%s\x1b[0m',`List: ${event.payload.item.metadata.name} ${web3.utils.fromWei(event.payload.base_price)}ETH`)
}
function handleSold(event) {
console.log('\x1b[33m%s\x1b[0m', `Sell: ${event.payload.item.metadata.name} ${web3.utils.fromWei(event.payload.sale_price)}ETH`)
}
client.onEvents(
slug,
[EventType.ITEM_LISTED, EventType.ITEM_SOLD],
(event) => {
// handle event
if (event.event_type === 'item_listed') {
handleList(event);
}
else if (event.event_type === 'item_sold') {
handleSold(event);
}
}
);