subscribe.py (303B)
1 import json 2 3 import websocket 4 5 ws = websocket.create_connection('ws://localhost:8545') 6 7 o = { 8 "jsonrpc": "2.0", 9 "method": "eth_subscribe", 10 "params": [ 11 "newHeads", 12 ], 13 "id": 0, 14 } 15 16 ws.send(json.dumps(o).encode('utf-8')) 17 18 while True: 19 print(ws.recv()) 20 21 ws.close()