-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
92 lines (80 loc) · 2.79 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
88
89
90
91
92
const ethers = require("ethers");
const axios = require("axios");
require("dotenv").config();
const rpcUrl = process.env.RPCURL;
//ORDINARY ABI FILE
const abiFile = require("./abi/abi.json");
//etherscan.io api key required for internally deployed contracts
const etherscanApiKey = process.env.ETHERSCANKEY;
async function main() {
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
let currentBlock = await provider.getBlockNumber();
while (1) {
try {
let liveBlock = await provider.getBlockNumber();
while (liveBlock >= currentBlock) {
let block = await provider.getBlockWithTransactions(currentBlock);
let txs = block.transactions;
currentBlock++;
for (let i = 0; i < txs.length; i++) {
let response;
//GET INTERNAL CONTRACT DEPLOYEMENT TXS
while (1) {
//RATE LIMITING
await new Promise((resolve) => setTimeout(resolve, 200));
response = await axios.get(
"https://api.etherscan.io/api?module=account&action=txlistinternal&txhash=" + txs[i].hash + "&apikey=" + etherscanApiKey + '"'
);
if (response.statusText === "OK") {
if (response.data.message === "NOTOK") {
console.log(response.data.result);
continue;
} else {
break;
}
}
}
for (let j = 0; j < response.data.result.length; j++) {
if (response.data.result[j].type === "create" && response.data.result[j].isError === "0") {
console.log("Created: " + response.data.result[j].contractAddress);
await spoofContract(response.data.result[j].contractAddress, provider);
}
}
//GET CONTRACT DEPLOYEMENT TXS
if (txs[i].creates != null) {
console.log("Created: " + txs[i].creates);
await spoofContract(txs[i].creates, provider);
}
}
}
} catch (err) {}
}
}
async function spoofContract(adr, provider, bot) {
let p1, p2, p3, p4, p5;
try {
const contract = new ethers.Contract(adr, abiFile, provider);
p1 = contract.name();
p1.then((a, b) => {
console.log(" Contract Name: " + a);
});
p2 = contract.symbol();
p2.then((a, b) => {
console.log(" Contract Symbol: " + a);
});
p3 = contract.owner();
p3.then((a, b) => {
console.log(" Contract Owner: " + a);
});
p4 = contract.totalSupply();
p4.then((a, b) => {
console.log(" Contract TotalSupply: " + a);
});
} catch (err) {
console.log(err);
}
return Promise.allSettled([p1, p2, p3, p4, p5]);
}
main().catch((a) => {
console.log(a);
});