当我想获取bsc mempool 中完整的tx,报错:too many arguments, want at most 1

我通过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())
请先 登录 后评论

最佳答案 2023-06-07 09:48

请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 0 收藏,1597 浏览
  • WeCheck 提出于 2023-06-06 22:28