Im trying to monitor EOA for the latest trasnactions and than send a notification.
I have this python code here:
from web3 import Web3
from web3.middleware import geth_poa_middleware
import time
web3 = Web3(Web3.HTTPProvider('bsc node/'))
web3.middleware_onion.inject(geth_poa_middleware, layer=0)
monitor = web3.toChecksumAddress('EOA to monitor')
def getBlock():
getLatest = web3.eth.get_block('latest')
print(web3.eth.get_block_number())
latest = getLatest.transactions
for i in latest:
txHash = Web3.toJSON(i).strip('"')
tx = web3.eth.get_transaction(txHash)
print(tx['from'])
if tx['from'] == monitor:
print('new tx sent')
while True:
getBlock()
time.sleep(1)
This code kinda works but the problem I have is that, it takes to long to process the transactions in a block, which makes the script skip blocks, hence I miss transactions.
Is there a better way to monitor accounts and the transactions in real time using python?