Solana py - Websocket Subscription to GetTokenAccountBalance
Solana py - Websocket Subscription to GetTokenAccountBalance
Loading saved threads...
Praveen · External communityPost link
External question — Solana Stack Exchange
Author: Praveen
Original post: https://solana.stackexchange.com/questions/9303
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Based on my research, I came to know that encoding = "base64" would solve the error "solders.SerdeJSONError: a list or single element". But when we try to subscribe to GetTokeAccountBalance, we''re not able to pass "encoding". It says unexpected argument has been recieved, which does make sense. There must be something wrong inside the package. Would you be able to give suggestions or any quick solutions for this issue?
Thanks in advance.
Quote
Report
solkla · External communityPost link
External answer — Solana Stack Exchange
Author: solkla
Original post: https://solana.stackexchange.com/a/13371
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
You gave me a nice hint with
encoding='base64'
as I tried
encoding='jsonParsed'
and it lead to the error you described.
I found out how to get the token balance, but for this you have to do some adjustments yourself.
await websocket.account_subscribe(vault_address, encoding='base64')
while True:
response = await websocket.recv()
if isinstance(response, list):
for item in response:
if isinstance(item, SubscriptionResult):
vault_subscription_id = item.result
elif isinstance(item, AccountNotification):
if isinstance(item.result.value, Account):
# here you need to decode item.result.value.data
# you can find out in Raydium SDK (typescript how they decode)
as soon as you decoded it, you can have the token account balance.
Hope I could help you or anybody else.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Solana Stack Exchange Author: solkla Source score (net votes, not local likes): 0 Original post: https://solana.stackexchange.com/a/13371 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. You gave me a nice hint with encoding='base64' as I tried encoding='jsonParsed' and it lead to the error you described. I found out how to get the token balance, but for this you have to do some adjustments yourself. await websocket.account_subscribe(vault_address, encoding='base64') while True: response = await websocket.recv() if isinstance(response, list): for item in response: if isinstance(item, SubscriptionResult): vault_subscription_id = item.result elif isinstance(item, AccountNotification): if isinstance(item.result.value, Account): # here you need to decode item.result.value.data # you can find out in Raydium SDK (typescript how they decode) as soon as you decoded it, you can have the token account balance. Hope I could help you or anybody else.
Checking account access…