0

CODE: This is on the EVM chain moonbeam network

from websocket import create_connection
import json
url = 'ws://xx.xx.xx.xx:9944/'
ws = create_connection(url)
ws.send(json.dumps({"id": 1, "method": "eth_subscribe", "params": ["newHeads"]}))
print (ws.recv())

Error from above code:

{'error': {'code': -32600, 'message': 'Unsupported JSON-RPC protocol version'}, 'id': 1}

Documentation:

https://docs.moonbeam.network/builders/get-started/eth-compare/rpc-support/

They have linked to the geth docs for the eth_subscribe method.

https://geth.ethereum.org/docs/rpc/pubsub#create-subscription

According to this, expected output is:

>> {"id": 1, "method": "eth_subscribe", "params": ["newHeads", {}]}
<< {"jsonrpc":"2.0","id":1,"result":"0xcd0c3e8af590364c09d0fa6a1210faf5"}

1 Answer 1

1

Your request should include "jsonrpc":"2.0". E.g.

{
  "jsonrpc":"2.0",
  "id": 1,
  "method": "eth_subscribe",
  "params": ["newHeads", {}]
}

See point 4 in https://www.jsonrpc.org/specification

1
  • Yes, I just figured it out but you are fast. Thanks :)
    – aste123
    Commented Feb 2, 2022 at 15:39

Your Answer

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

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