Example - Minting Scanner

Dependencies

yarn add @scamsniffer/detector websocket
minting-scanner.js
const WebSocket = require("websocket").w3cwebsocket;
const { DetectorAPI } = require("@scamsniffer/detector");
const API_KEY = '';
const ENDPOINT = 'http://localhost';
const detectorApi = new DetectorAPI({
apiKey: API_KEY,
endpoint: ENDPOINT
});
const allScanTask = [];
const allUniqueUrls = new Set();
async function runTask(task) {
console.log('detect', task)
const result = await detectorApi.detect(task.link);
if (!result.isSafe) {
console.log('result', result, task)
}
}
async function doScan() {
for (let index = 0; index < Infinity; index++) {
const task = allScanTask.shift();
if (task) {
try {
await runTask(task);
} catch(e) {}
}
await new Promise((resolve) => {
setTimeout(resolve, 2 * 1000);
})
}
}
async function addTask(task) {
allScanTask.push(task);
}
function listenMintingNow() {
const socket = new WebSocket("wss://api.icy.tools/events/graphql", [
"graphql-ws",
]);
// Connection opened
socket.onopen = function (event) {
socket.send(JSON.stringify({ type: "connection_init", payload: {} }));
socket.send(
JSON.stringify({
id: "1",
type: "start",
payload: {
variables: {},
extensions: {},
operationName: "OnSync",
query:
"subscription OnSync {\n onSync {\n contracts\n fromBlock\n toBlock\n wallets\n __typename\n }\n}",
},
})
);
socket.send(
JSON.stringify({
id: "2",
type: "start",
payload: {
variables: {},
extensions: {},
operationName: "OnPendingMints",
query:
"subscription OnPendingMints {\n onPendingMints {\n address\n count\n__typename\n }\n}",
},
})
);
socket.send(
JSON.stringify({
id: "3",
type: "start",
payload: {
variables: { filter: { period: "ONE_HOUR" } },
extensions: {},
operationName: "OnTrendingMintsUpdated",
query:
"subscription OnTrendingMintsUpdated($filter: TrendingMintsFilterInput!) {\n onTrendingMintsUpdated(filter: $filter) {\n ...TrendingMint\n __typename\n }\n}\n\nfragment TrendingMint on TrendingMint {\n count\n distinct\n firstMintedAt\n index\n sum\n distinctSum\n estMintCost\n avgTxFeeInEth\n avgGasPriceInGwei\n maxSupply\n address\n description\n discordUrl\n externalUrl\n imageUrl\n instagramUsername\n name\n slug\n symbol\n telegramUrl\n twitterUsername\n uuid\n icySlug\n deltaStats {\n count\n index\n__typename\n }\n __typename\n}",
},
})
);
};
socket.onmessage = function (event) {
const data = JSON.parse(event.data);
const hasPayload = data.payload;
if (!hasPayload) return;
const onTrendingMintsUpdated = data.payload.data.onTrendingMintsUpdated;
if (onTrendingMintsUpdated) {
// console.log("onTrendingMintsUpdated", new Date());
const hasUrlCollections = onTrendingMintsUpdated.filter(
(_) =>_.externalUrl
);
hasUrlCollections.forEach((_) => {
const { externalUrl, imageUrl, name, address } =_;
if (!allUniqueUrls.has(externalUrl)) {
const collectionInfo = {
name,
externalUrl,
address,
imageUrl,
};
// console.log("newCollection", allUniqueUrls.size, collectionInfo);
allUniqueUrls.add(externalUrl);
addTask({
link: externalUrl,
...collectionInfo,
});
}
});
}
};
socket.onclose = function (e) {
setTimeout(function () {
listenMintingNow();
}, 1000);
};
}
async function main() {
listenMintingNow();
doScan();
}
main();
Copy link