Is it possible to take the token account creation fee from the wallet to which the token will be sent? Would they need to sign the transaction in order to achieve this?
2 Answers
It would only be possible to take the token account creation fee from the target of the account if the target also signed the transaction.
As mentioned in another answer, it is possible. If the traget is the payer, it has to be a signer as well.
Here's an example on how it could look like with Anchor:
#[derive(Accounts)]
pub struct CreateTokenAcct<'info> {
#[account(mut)]
pub user: Signer<'info>,
#[account(mut)]
pub target: Signer<'info>,
pub mint: Account<'info, Mint>,
#[account(init, payer = target, associated_token::mint = mint, associated_token::authority = target)]
pub destination: Account<'info, TokenAccount>,
pub system_program: Program <'info, System>,
pub token_program: Program<'info, Token>,
pub associated_token_program: Program<'info, AssociatedToken>,
pub rent: Sysvar<'info, Rent>,
}
-
2It's not necessary to use
init_if_needed
here and it's generally considered bad practice to use– Henry ECommented Jul 25, 2022 at 18:23 -
1Good point. I edit the answer to not use
init_if_needed
. Commented Jul 25, 2022 at 18:41