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

_create_account_info returns "Invalid account size" when using TOKEN_2022_PROGRAM_ID #463

Open
0xtakamaka opened this issue Nov 14, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@0xtakamaka
Copy link

0xtakamaka commented Nov 14, 2024

I am running solana-py on ECLIPSE, which uses TOKEN_2022_PROGRAM_ID for most tokens.

When I do "token.get_or_create_associated_token_account(keypair.pubkey(), payer=keypair, create=True)" it returns error, as len(bytes_data) != ACCOUNT_LAYOUT.sizeof() inside "_create_account_info" triggers ValueError("Invalid account size")

ACCOUNT_LAYOUT for TOKEN_2022_PROGRAM_ID is probably different? Can anybody help?

@0xtakamaka 0xtakamaka changed the title _create_account_info returns "Invalid account size _create_account_info returns "Invalid account size" when using TOKEN_2022_PROGRAM_ID Nov 14, 2024
@michaelhly
Copy link
Owner

What version of solana-py are you using?

@0xtakamaka
Copy link
Author

I am using latest, v0.35.1. Do you have any suggestions what can be wrong?

@michaelhly
Copy link
Owner

You need to pass in TOKEN_2022_PROGRAM_ID as the 4th argumeht:

def create_associated_token_account(
payer: Pubkey, owner: Pubkey, mint: Pubkey, token_program_id: Pubkey = TOKEN_PROGRAM_ID
) -> Instruction:

@0xtakamaka
Copy link
Author

i did this, but len(bytes_data) != ACCOUNT_LAYOUT.sizeof() inside _create_account_info still triggers an error as len(bytes_data) is 170, while ACCOUNT_LAYOUT.sizeof() is 165

@michaelhly
Copy link
Owner

Okay. This is a bug. We'll need to patch.

@michaelhly michaelhly added the bug Something isn't working label Nov 26, 2024
@rdong8
Copy link

rdong8 commented Dec 4, 2024

Am also encountering this with:

import asyncio

from solana.rpc.async_api import AsyncClient
from solders.keypair import Keypair
from solders.pubkey import Pubkey
from spl.token.async_client import AsyncToken


async def main() -> None:
    client = AsyncClient("https://api.mainnet-beta.solana.com")

    token = AsyncToken(
        conn=client,
        pubkey=Pubkey.from_string(
            "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo"  # PYUSD
        ),
        program_id=Pubkey.from_string(
            "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"  # Token-2022
        ),
        payer=Keypair(),
    )

    print(token.get_mint_info())


if __name__ == "__main__":
    asyncio.run(main())

Also, create_idempotent_associated_token_account currently hardcodes TOKEN_PROGRAM_ID so it cannot be used with Token 2022 tokens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants