1

I am trying to create an ATA using this but i get this error

#[account(
init,
payer = signer,
seeds = [rent_manager.key().as_ref()],
bump,
token::mint = pay_mint,
token::authority = rent_manager,
)]
pub rent_manager_vault: Account<'info, TokenAccount>,

enter image description here

1
  • Please copy the logs and paste the text instead of an image.
    – Jacob Creech
    Commented Sep 20, 2022 at 1:33

3 Answers 3

2

An associated token account by definition already uses its own set of seeds. Try removing the seeds constraint and see if that helps. And update to using the correct associated token constraints:

#[account(
    init,
    payer = payer,
    associated_token::mint = mint,
    associated_token::authority = payer,
)]
pub token: Account<'info, TokenAccount>,
1

The error was due to i was using wrong seeds for rent_manager_vault

0

To create an associated token account you need to pass ATA program ID and use the anchor_spl crate with associated_token.

use anchor_spl::{associated_token::AssociatedToken}

....

   #[account(
    init_if_needed,
    payer = signer,
    associated_token::mint = pay_mint,
    associated_token::authority = rent_manager,
    )]
    rent_manager_vault: Account<'info, TokenAccount>,

    ...

    associated_token_program: Program<'info, AssociatedToken>,
2
  • This wont work as ATA is a PDA an it wont work with custom seeds
    – Pratik.js
    Commented Sep 19, 2022 at 17:07
  • 1
    Oh yes makes sense
    – maddy
    Commented Sep 19, 2022 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.