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

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..



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yilmaz