-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathFindBots.py
More file actions
41 lines (32 loc) · 1.66 KB
/
FindBots.py
File metadata and controls
41 lines (32 loc) · 1.66 KB
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
##From the Console Cowboys Youtube Series
## Uses the web3.py API to pull down transactions in the latest block
## Then finds likily bot activity and prints out possible Frontrunning and Sandwich attacks
## @ficti0n on twitter
#------------------------------------------------------------------------------------------
from web3 import Web3
#------------------------Setup Variables and Connections--------------------#
web3 = Web3(Web3.HTTPProvider('ADD YOUR HTTP INFURA URL'))
block = web3.eth.get_block('latest')
toFromPairs = {}
transactionCount = {}
#------------------------Setup Variables and Connections--------------------#
#--------------------Begin Main Code Block-----------------------------------#
#Grab our Transactions and thier transaction hashes
if block and block.transactions:
for transaction in block.transactions:
tx_hash = transaction.hex() # Convert txhashes from hexBytes format
tx = web3.eth.get_transaction(tx_hash)
#Check if To/From pairs exist and update count
if tx.to != None:
if tx.to in toFromPairs:
if toFromPairs[tx.to] == tx["from"]:
transactionCount[tx.to] = transactionCount[tx.to] +1
#Start a running count on any new To addresses and create a to/from pair
elif tx.to not in toFromPairs:
transactionCount[tx.to] = 1
toFromPairs[tx.to] = tx["from"]
#-------------------- End Main Code Block------------------------------------#
#Print all pairs with exactly 2 transactions in a single block for manual review
for key, value in transactionCount.items():
if value == 2:
print(toFromPairs[key])