Yes, it is possible for a PDA to pay for initializing an account. The trick is that a PDA needs to be owned by the system program but signed for by the program the PDA is derived from. Note that I've added the signer
constraint, modified the account type to SystemAccount
. You'll also need a seeds::program
constraint if the program signing is different from the program executing this instruction.
#[account(
signer,
mut,
seeds = [some_seeds],
bump,
seeds::program = [program_account]
)]
payer: SystemAccount<'info>,
#[account(init, payer = payer, space = some_space, owner = some_owner)]
inited_account: AccountInfo<'info>,
You also don't necessarily have to check the seeds here, unless required for security reasons.
#[account(mut)]
payer: Signer<'info>,
#[account(init, payer = payer, space = some_space, owner = some_owner)]
inited_account: AccountInfo<'info>,