I run geth with this command
geth --syncmode "fast" --cache 2048 --datadir /data/ethereum --ws --wsaddr 0.0.0.0 --wsorigins '*' --wsapi 'web3,eth,net,db,personal' --rpc --rpcaddr 0.0.0.0
then i subscribe newHeads and recieve {"jsonrpc":"2.0","id":1,"result":"0x30ebfd74dc99548d16b64d23eda6f964"}
.But can not recieve any block head.I try to connect infura wss://mainnet.infura.io/ws
and recieve new block head.
import websocket
import json
import time
try:
import thread
except ImportError:
import _thread as thread
def on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
def run(*args):
ws.send(json.dumps({"id": 1, "method": "eth_subscribe", "params": ["newHeads"]}))
print("thread terminating...")
thread.start_new_thread(run, ())
if __name__ == "__main__":
websocket.enableTrace(True)
# ws = websocket.WebSocketApp("wss://mainnet.infura.io/ws",
ws=websocket.WebSocketApp("ws://127.0.0.1:8546",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
Am I wrong ? My geth version is Geth/v1.9.6-stable-bd059680/linux-amd64/go1.13.1.
Thanks