Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: object solders.rpc.responses.GetAccountInfoResp can't be used in 'await' expression #107

Closed
artaasd95 opened this issue Jan 8, 2023 · 1 comment

Comments

@artaasd95
Copy link

artaasd95 commented Jan 8, 2023

Hi, I want to instantiate a program account and then fetch it as documentation.

from my_client.accounts import PostAccount
connection = Client("https://api.devnet.solana.com")

addr = PublicKey("...")

acc = await PostAccount.fetch(connection, addr)
if acc is None:
   
    raise ValueError("account not found")


obj = acc.to_json()
print(obj)

acc_from_json = PostAccount.from_json(obj)

This is like documentation. And the error:

TypeError                                 Traceback (most recent call last)
f:\programming\intelligent_dex\core_calculations\tests.ipynb Cell 8 in <cell line: 4>()
      [1](vscode-notebook-cell:/f%3A/programming/intelligent_dex/core_calculations/tests.ipynb#X11sZmlsZQ%3D%3D?line=0) # fetch an account
      [2](vscode-notebook-cell:/f%3A/programming/intelligent_dex/core_calculations/tests.ipynb#X11sZmlsZQ%3D%3D?line=1) addr = PublicKey("FJLoTgfa5QErRQXsKJrx2ULipJQBRfxVd5zs1jzA18W3")
----> [4](vscode-notebook-cell:/f%3A/programming/intelligent_dex/core_calculations/tests.ipynb#X11sZmlsZQ%3D%3D?line=3) acc = await PostAccount.fetch(connection, addr)
      [5](vscode-notebook-cell:/f%3A/programming/intelligent_dex/core_calculations/tests.ipynb#X11sZmlsZQ%3D%3D?line=4) if acc is None:
      [6](vscode-notebook-cell:/f%3A/programming/intelligent_dex/core_calculations/tests.ipynb#X11sZmlsZQ%3D%3D?line=5)     # the fetch method returns null when the account is uninitialized
      [7](vscode-notebook-cell:/f%3A/programming/intelligent_dex/core_calculations/tests.ipynb#X11sZmlsZQ%3D%3D?line=6)     raise ValueError("account not found")

File f:\programming\intelligent_dex\core_calculations\my_client\accounts\post_account.py:52, in PostAccount.fetch(cls, conn, address, commitment, program_id)
     44 @classmethod
     45 async def fetch(
     46     cls,
   (...)
     50     program_id: PublicKey = PROGRAM_ID,
     51 ) -> typing.Optional["PostAccount"]:
---> 52     resp = await conn.get_account_info(address, commitment=commitment)
     53     info = resp.value
     54     if info is None:

TypeError: object solders.rpc.responses.GetAccountInfoResp can't be used in 'await' expression

Please help.
Thanks

@kevinheavey
Copy link
Owner

You need to use AsyncClient, not Client. I recommend using a type checker such as mypy to catch things like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants