0

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

1 Answer 1

1

Please check whether your Geth node is completely synced

6
  • only full sync support subscribe?
    – egodcore
    Oct 30, 2019 at 5:57
  • no, Fast sync will support subscription, what I just meant is to check whether the node synced completely or not?
    – Akshay Dev
    Oct 30, 2019 at 7:44
  • oh, i checkecd that the node synced completely. But steel can not recieve response
    – egodcore
    Oct 30, 2019 at 8:47
  • try this on your terminal -- > wscat -c "ws://127.0.01:8546" then > {"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["newHeads"]}
    – Akshay Dev
    Oct 30, 2019 at 9:37
  • 1
    sorry, I checked sync again. The node is not synced completely...
    – egodcore
    Oct 31, 2019 at 4:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.