我通过websockets发送:
'{"id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions", true]}'
而且应该得到完整的交易细节而不是哈希值。
但得到的是错误:
{"error":{"code":-32602,"message":"too many arguments, want at most 1"},"id":1,"jsonrpc":"2.0"}
如果我发送:
{ jsonrpc: '2.0',method: 'eth_subscribe',params:['newPendingTransactions'],id: 1}
则正常得到TX的哈希值。
为啥会是这样呢 ?
Python代码如下:
import asyncio
import json
from websockets import connect
ws_url = 'wss://bsc.getblock.io/xxxxxx/mainnet/'
async def get_event():
async with connect(ws_url) as ws:
await ws.send(
'{"id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions", true]}')
subscription_response = await ws.recv()
print(subscription_response)
while True:
try:
message = await asyncio.wait_for(ws.recv(), timeout=15)
response = json.loads(message)
print(response)
pass
except:
pass
if __name__ == "__main__":
loop = asyncio.get_event_loop()
while True:
loop.run_until_complete(get_event())