Go-Ethereum
使用 eth_subscribe 時出現錯誤 {’error’: {‘code’: -32600, ‘message’: ‘Unsupported JSON-RPC protocol version’}, ‘id’: 1}
程式碼:這是在 EVM 鏈月光網路上
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': {'code': -32600, 'message': 'Unsupported JSON-RPC protocol version'}, 'id': 1}
文件:
https://docs.moonbeam.network/builders/get-started/eth-compare/rpc-support/
他們已連結到該
eth_subscribe
方法的 geth 文件。https://geth.ethereum.org/docs/rpc/pubsub#create-subscription
據此,預期輸出為:
>> {"id": 1, "method": "eth_subscribe", "params": ["newHeads", {}]} << {"jsonrpc":"2.0","id":1,"result":"0xcd0c3e8af590364c09d0fa6a1210faf5"}
您的請求應包括
"jsonrpc":"2.0"
. 例如{ "jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["newHeads", {}] }