Hi,
I use this code for monitor a ETH address
code from: Web3.py: How to Monitor ETH Transfers to an Address
but even I delete “time.sleep(5)”, it is too slow to search a block, It takes more than 30 seconds to search a block, but Ethereum average block time is at a current level of 12s, so blocks will definitely be missed, how can I solve this problem?
def watch():
while True:
block = web3.eth.get_block(‘latest’)
print("Searching in block " + str(block.number))
if block and block.transactions:
for transaction in block.transactions:
tx_hash = transaction.hex() # the hashes are stored in a hexBytes format
tx = web3.eth.get_transaction(tx_hash)
if tx.to != None:
if tx.to == account:
print("Transaction found in block {} :".format(block.number))
print({
"hash": tx_hash,
"from": tx["from"],
"value": web3.fromWei(tx["value"], 'ether')
})
time.sleep(5)
watch()