5 OK链如何监听链上数据

tx_filter = w3.eth.filter('pending')
block_filter = w3.eth.filter('latest')
Traceback (most recent call last):
  File "sniper.py", line 100, in <module>
    startTx()
  File "sniper.py", line 79, in startTx
    loop.run_until_complete(asyncio.gather(log_loop(tx_filter)))
  File "/Users/zhong/opt/anaconda3/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "sniper.py", line 72, in log_loop
    for event in event_filter.get_new_entries():
  File "/Users/zhong/opt/anaconda3/lib/python3.8/site-packages/web3/_utils/filters.py", line 160, in get_new_entries
    log_entries = self._filter_valid_entries(self.eth_module.get_filter_changes(self.filter_id))
  File "/Users/zhong/opt/anaconda3/lib/python3.8/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/Users/zhong/opt/anaconda3/lib/python3.8/site-packages/web3/manager.py", line 198, in request_blocking
    return self.formatted_response(response,
  File "/Users/zhong/opt/anaconda3/lib/python3.8/site-packages/web3/manager.py", line 171, in formatted_response
    raise ValueError(response["error"])
ValueError: {'code': -32000, 'message': 'the method is not allowed'}

监听提示这个,有没有什么办法解决,或者ok链本身就不是这样监听的。 希望有大佬看看


async function startConnection() {
provider.on('pending', async (txHash) => {
setTimeout(async () => {
try {
let tx = await provider.getTransaction(txHash);
console.log(tx)
} catch (err) {
console.error(`${txHash} ${err}`)
}
})
});
};

{
hash: '0x14370514efab5a5039fda16269d964f92487856ce41448a9b6bffab3645f05a3',
type: null,
accessList: null,
blockHash: null,
blockNumber: null,
transactionIndex: null,
confirmations: 0,
from: '0x68A74dc424FD6869523A638226bc042F842e8780',
gasPrice: BigNumber { _hex: '0x1183e41f', _isBigNumber: true },
gasLimit: BigNumber { _hex: '0x01a75d', _isBigNumber: true },
to: null,
value: BigNumber { _hex: '0x00', _isBigNumber: true },
nonce: 179,
data: '0x60566050600b82828239805160001a6073146043577f4e487b7100000000000000000000000000000000000000000000000000000000600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220c2479b82d61d66868fed053bc1a04983132aa46aa4bb45da7cbeabf966daaee764736f6c634300080d0033',
r: '0x7731d44a7b3727c2803ddba555f83da6f7add9d2d405845c73655ea3d595ed80',
s: '0x087937e9599a4eb471da9a37b4697e20a749837e25c6ad44a31c12ab74e1068f',
v: 168,
creates: '0x84686FAD5649d3352865993C12fd0f1eec3749FD',
chainId: 66,
wait: [Function (anonymous)]
}

用Js可以正常获取



const provider = new ethers.providers.WebSocketProvider('wss://exchainws.okex.org:8443')
请先 登录 后评论

最佳答案 2022-04-20 14:38

节点需要支持 websocket , 如果节点一样,而用 JS 可以获取, 那么应该是你 Python 代码的问题。

请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 0 收藏,2703 浏览
  • raven 提出于 2022-04-20 14:03