-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
87 lines (71 loc) · 2.48 KB
/
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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict'
const ethers = require('ethers');
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});
const { RPC_URL_HTTP_ENDPOINT } = require('./config');
const ERC721 = require('./abi/ERC721.json');
//define & initizlize ethers project
const provider = new ethers.providers.JsonRpcProvider(RPC_URL_HTTP_ENDPOINT);
//define data items
var collectedAddresses = [], startBlock, lastBlock;
/**
* @description input the number of start block
*/
const initApp = async () => {
//read blocknumber from console readline
readline.question("Please input block number: ", async (blockNumber) => {
startBlock = blockNumber;
lastBlock = await provider.getBlockNumber();
await mainProcess(startBlock, lastBlock);
})
}
/**
*
* @param {String} startBlock
* @param {String} lastBlock
* @description get blocks between two block numbers from parameter and
* get ERC721 creation transactions for each block
*/
const mainProcess = async (startBlock, lastBlock) => {
console.log("\nSearching...");
let block;
for (let i = startBlock; i <= lastBlock; i++) {
//get block and transactions from blocknumber
try {
block = await provider.getBlockWithTransactions(Number(i));
console.log(`Block ${i}_>`);
} catch (err) {
continue;
}
//scan each transaction in block
for await (const transaction of block.transactions) {
//check if any smart contract created with this transaction
if (transaction?.creates !== null) {
//check if created smart contract is ERC721 or not
try {
const contract = new ethers.Contract(transaction?.creates, ERC721.abi, provider);
const isERC721 = await contract.supportsInterface('0x80ac58cd');
if(isERC721) {
collectedAddresses.push(transaction?.creates);
}
else {
continue;
}
} catch (_) {
continue;
}
}
}
//print result on console
if (collectedAddresses.length > 0) {
console.log(`For block ${i}: `, collectedAddresses);
collectedAddresses = [];
console.log("\nSearching...");
}
}
//close console readline
readline.close();
}
initApp(); //start app