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

Anchor does not support init_if_needed for token2022 like it does for normal tokens #3498

Open
michaelangelo3337 opened this issue Jan 19, 2025 · 0 comments

Comments

@michaelangelo3337
Copy link

Anchor does not support init_if_needed for token2022 like it does for normal tokens

For hours I was wondering why my program would break when I would switch my token to 2022, even thought correctly switched to TransferChecked and gave in all the correct details and derived the ATA in the front end by specifically clarifying it was a token2022 program ATA. For hours I jumped from hoop to hoop trying to figure out what was wrong.

Turns out if you are using token2022 you must explicitly include in your init_if_needed that it is a token2022 which I did not think would be the case because you are providing the correct mint and anchor should easily be realizing the correct token program from the mint you gave in because the mint toAccountInfo has an owner field with the token2022 or normal token program ID.

#[account(mut, associated_token::mint = mint_account, associated_token::authority = ata, associated_token::token_program = token2022_program)]

However you need to explicitly say this in your instruction associated_token::token_program = token2022_program

And nowhere in any anchor example, solana program docs or github do they show you must do this. I had to figure it out myself and not a single stackoverflow online shows this.

This can be very troubling for devs, especially ones that don't understand solana as well as I do and wont be able to come to the fix.

You guys must change it so Anchor automatically determines the toke_program without needing to explicitly say it because it is obviously given in the mint account.

Because this is the whole entire point of Anchor, to make it easier and more use friendly, otherwise we would just use the normal solana program with plain rust.

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

1 participant