the trait `anchor_lang::AccountDeserialize` is not implemented for `anchor_spl::token::Mint`

1.2k views Asked by At

I am trying to CPI the Token Program to send spl-tokens to a wallet. For this the derive accounts in the context struct has three accounts without any attribute over them:

  1. mint_token_out: Account<'info, Mint> (which is the mint address)
  2. token_out: Account<'info, TokenAccount>(which is the token account that the token would be sent out from) and
  3. token_program: Program<'info, Token>.

But I get four Trait not implemented errors. They are:

  1. the trait AccountSerialize is not implemented for anchor_spl::token::Mint at line --- mint_token_out
  2. the trait anchor_lang::AccountDeserialize is not implemented for TokenAccount at line --- token_out: Account<'info, TokenAccount>
  3. the trait anchor_lang::Owner is not implemented for TokenAccount at line --- token_out: Account<'info, TokenAccount>
  4. the trait anchor_lang::Owner is not implemented for anchor_spl::token::Mint at line --- mint_token_out: Account<'info, Mint>

Is there something wrong I'm doing?

I have tried adding the constraint #[account(mut, has_one = wallet, owner = wallet)] as the account attribute for mint_token_out. But I still get the error..

1

There are 1 answers

0
Yilmaz On

That error indicates that you did not use #[derive(Accounts)] for the related struct that you created for the method.

#[derive(Accounts)]
pub struct YourTructForContext<'info>{}

#[derive(Accounts)] Implements an Accounts deserializer on the given struct. Meaning it allows this struct to process user addresses and accounts.