-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.py
114 lines (93 loc) · 3.69 KB
/
checker.py
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
import sys
from os.path import join, dirname
import argparse
from web3 import Web3
from dotenv import load_dotenv
dotenv_path = join(dirname(__file__), ".env")
load_dotenv(dotenv_path)
key = os.environ.get("WEB3_INFURA_PROJECT_ID")
parser = argparse.ArgumentParser()
# checker allow to research created token in three ways
# for a specific block, from a range of block , and stream the network for new created block
# default setting stream the ethereum nainnet node
parser.add_argument("--block", type=int)
parser.add_argument("--range", type=int, nargs=2)
# list of standard function for ERC721 token encode in keccak2563
ERC721_KeyWord = [
"70a08231", # balanceOf(address)
"6352211e", # ownerOf(uint256)
"42842e0", # safeTransferFrom(address,address,uint256)
"b88d4fde", # safeTransferFrom(address,address,uint256,bytes)
"23b872dd", # transferFrom(address,address,uint256)
"095ea7b3", # approve(address,uint256)
"081812fc", # getApprove(uint256)
"a22cb465", # setApprovalForAll(address,bool)
"e985e9c5", # isApprovedForAll(address,address)
"17307eab", # ApprovalForAll(address,address,bool)
"c87b56dd", # tokenURI(uint256)
"2f745c59", # tokenOfOwnerByIndex(address,uint256)
]
# HTTPS provider, this project use INFURA, don't forget to add your key to .env file
w3 = Web3(Web3.HTTPProvider(f"https://mainnet.infura.io/v3/{key}"))
def tx_checker(blockData):
array = []
results = []
block = w3.eth.get_block(blockData, True)
transactions = block["transactions"]
for transaction in transactions:
receipt = w3.eth.get_transaction_receipt(transaction["hash"].hex())
receipt_logs = receipt["contractAddress"]
# check if new addresses are created inside the block
if receipt_logs != None:
results.append(receipt_logs)
print(f"address {receipt_logs} has been created during block {blockData}")
for result in results:
checker_count = 0
address = str(result)
try:
bytecode = w3.eth.get_code(address)
string = str(bytecode.hex())
for item in ERC721_KeyWord:
# compare the bytecode with the standards ERC721 functions bytecode
if item in string:
checker_count += 1
# print(checker_count)
if checker_count >= len(ERC721_KeyWord) - 1:
if result not in array:
array.append(result)
print(f"{result} is a ERC721 token")
except ValueError:
# print("this contract is not verified")
pass
return array
def main(argv=None):
parse = parser.parse_args(argv)
blockNumber = parse.block
rangeblock = parse.range
startBlock = w3.eth.get_block_number()
blockTo = int(startBlock)
# list of new created NFTs
list_address = []
if blockNumber:
print(f"fetching for block {blockNumber}")
list_address = tx_checker(blockNumber)
elif rangeblock:
blockInit = rangeblock[0]
for x in range(rangeblock[0], rangeblock[1]):
print(f"fetching for block {blockInit}")
tx_checker(blockInit)
if tx_checker(blockInit) != []:
list_address = tx_checker(blockInit)
blockInit += 1
else:
while True:
print(f"fetching for block {blockTo}")
list_address = tx_checker(blockTo)
if len(list_address) > 0:
print(f"list of ERC721 {blockTo} is {list_address}")
blockTo += 1
print(f"list of ERC721 is {list_address}")
return list_address
if __name__ == "__main__":
sys.exit(main())