You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: