solana-py
solana-py copied to clipboard
How to use set_log_filter function in solana rpc client
I tried to get all logs of solana network with following code
solana_client = Client(cfg.SOL_RPC_URL)
filter = solana_client.set_log_filter("solana_core=debug")
while True:
await filter.update()
items = filter.items()
print(items)
for log in items:
await handle_log(log)
time.sleep(poll_interval)
But such error occurred
{'jsonrpc': '2.0', 'error': {'code': -32601, 'message': 'Method not found'}, 'id': 1}
What's the reason of this error?
where did you get this code from? I see that you are awaiting a non coroutine object.
Client is sync and not async. you will need to use AsyncClient.
then what is update()? and items()? and you cannot use time.sleep()
in asyncio, you will have to use asyncio.sleep()
Can you give me a code to listen transaction from network. I used websocket client, but it sometimes is disconnected and therefore can't listen some transaction.
Can you give me a code to listen transaction from network. I used websocket client, but it sometimes is disconnected and therefore can't listen some transaction.
here you go.
import asyncio
from solana.rpc.websocket_api import connect
async def main():
async with connect("wss://api.devnet.solana.com") as websocket:
await websocket.logs_subscribe() # or .account_subscribe("address")
first_resp = await websocket.recv()
subscription_id = first_resp.result
next_resp = await websocket.recv()
print(next_resp)
await websocket.logs_unsubscribe(subscription_id)
asyncio.run(main())
I used that code.
But if wss connection break down because some network state, we need to reconnect that, it take more than a min. so we can't receive logs in that time.
So I tried to use web3 endpoint like ethereum.
I used that code.
But if wss connection break down because some network state, we need to reconnect that, it take more than a min. so we can't receive logs in that time.
So I tried to use web3 endpoint like ethereum.
use while 1: it will run indefinitely.
LOL. if connection closed, we need to reconnect, it take some time. we can't get logs during that time.
LOL. if connection closed, we need to reconnect, it take some time. we can't get logs during that time.
alright. goodluck then.
note that github is with issues related to the code. you might find an answer on stackoverflow.
Thanks for your time. Why you answer my question. You aren't enough to answer.
The set_log_filter
RPC method seems to be removed from the Solana nodes. We should remove this RPC method.
@michaelhly So there aren't any way to get real time logs from node without use wss?
No. There is not.
Okay. thanks.
The
set_log_filter
RPC method seems to be removed from the Solana nodes. We should remove this RPC method.
Closed by #291