I'm trying to learn solana and currently doing NFTs. I'm wondering if it's possible to create an Associated Token Account with an owner that differs from the signer and then mint an NFT to that ATA? Kind of like an Airdrop. For some reason creating an ATA to use it for a transfer works the way it's supposed to, but when I use that exact same ATA for minting, I get an error. In my .ts file, when I create the ATA, I of course use the payer as the original account that is supposed to sign the transaction and the owner as the account that is supposed to get the tokens.
Also I have a pretty trivial question what authority stands for in Solana programs?
The code of the program where I have the issue:
pub fn mint_token(ctx: Context<MintToken>,) -> Result<()> {
let cpi_accounts = MintTo {
mint: ctx.accounts.mint.to_account_info(),
to: ctx.accounts.token_account.to_account_info(),
authority: ctx.accounts.authority.to_account_info(),
};
let cpi_program = ctx.accounts.token_program.to_account_info();
let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
token::mint_to(cpi_ctx, 1)?;
Ok(())
}
#[derive(Accounts)]
pub struct MintToken<'info> {
/// CHECK: This is the token that we want to mint
#[account(mut)]
pub mint: UncheckedAccount<'info>,
pub token_program: Program<'info, Token>,
/// CHECK: This is the token account that we want to mint tokens to
#[account(mut)]
pub token_account: UncheckedAccount<'info>,
/// CHECK: the authority of the mint account
#[account(mut)]
pub authority: AccountInfo<'info>,
}
pub user_signer: AccountInfo<>