Hello,
I try to capture all tranasctions sent to a Uniswap pool (eth/wbtc 0.05 0x4585FE77225b41b697C938B018E2Ac67Ac5a20c0) but i dont capture any results but i do see new transactions arrived on the Uniswap web app, i updated the code based on your example from here to my needs:
import json
import asyncio
from web3 import Web3
from websockets import connect
infura_ws_url = 'wss://mainnet.infura.io/ws/v3/XXX5e35dfa6f4d4289141b08d552XXX'
web3 = Web3(Web3.WebsocketProvider(infura_ws_url))
# Uniswap pool address
account = '0x4585FE77225b41b697C938B018E2Ac67Ac5a20c0'
async def get_event():
async with connect(infura_ws_url) as ws:
await ws.send('{"jsonrpc": "2.0", "id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}')
subscription_response = await ws.recv()
print(subscription_response)
while True:
try:
message = await asyncio.wait_for(ws.recv(), timeout=15)
response = json.loads(message)
txHash = response['params']['result']
# print('txHash: ' + txHash)
tx = web3.eth.get_transaction(txHash)
print('tx: ' + tx['to'].lower())
if tx['to'].lower() == account.lower():
print("Pending transaction found with the following details:")
print({
"hash": txHash,
"from": tx["from"],
"value": web3.from_wei(tx["value"], 'ether')
})
pass
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
while True:
loop.run_until_complete(get_event())
when executing the code:
>>> %Run -c $EDITOR_CONTENT
{"jsonrpc":"2.0","id":1,"result":"0x6727fce65300426ba5c04406d3c924a3"}
tx: 0x75e89d5979e4f6fba9f97c104c2f0afb3f1dcb88
tx: 0xdef171fe48cf0115b1d80b88dc8eab59176fee57
tx: 0x7ff29bd08af26495eeb96cb5d80f1813c0410917
tx: 0x4c35bce0a43574d259eb523e85af193ce0fb6c91
tx: 0x888888888889758f76e7103c6cbf23abbf58f946
tx: 0x484125486a45c20b736b2e4a6059c927d8a9da6f
tx: 0x3c2f67693328a253b0461e83d4b8c01f59426613
.
.
.
.
.
tx: 0x0d1a4cf8c73af2c7211cde6f4ebb756758371959
tx: 0x561c0246e58db7b89c3205137f2d285b9ef806c1
tx: 0xdac17f958d2ee523a2206206994597c13d831ec7
tx: 0x20f3064f787f6124a9a20332de91fbfd6a91d6bf
tx: 0x90fb64f8895bcfda1a730a3f0804c8467afbe65f
tx: 0x9164b7d3ab0b5e26cff7416f911d461c505f20f6
but there are no new printouts of “Pending transaction found” while in the Uniswap web app:
External Image
can you please point me out to what is it I’m missing here?
Many many thanks in advanced as this drives me nuts
Cheers,
RS