3

Is it possible to use a PDA as the payer in an anchor init macro. If so how? I have tried simply setting the payer to be a PDA but have received the error.

"signer privilege escalated"

    #[account(mut, seeds = [some_seeds], bump)]
    payer: AccountInfo<'info>,
    #[account(init, payer = payer, space = some_space, owner = some_owner)]
    inited_account: AccountInfo<'info>,
    

2 Answers 2

8

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>,
6
  • How are you signing the create account tx via the pda in the second snippet. without passing in the seeds and bump to be used for invoke_signed ix ? also wdnt Signer type fail as a client will pass the pda signed field as false ? only when the program does a ix can it sign for the pda. unless my understanding of the signer type is incomplete. Commented Jul 23, 2022 at 21:58
  • - Signatures come from outside the transaction itself. How to sign a transaction with a PDA is a separate question. This is an example of a function that can the question asker intends to call via CPI. - No, when constructing the CPI transaction, the program handles assigning the meta account information - yes, if you want to sign with a PDA then only a program can send the transaction. But this account struct allows for any type of signer.
    – Henry E
    Commented Jul 23, 2022 at 21:59
  • The assumption here is op ix will get called by another program ix so as to sign via the pda and pass that sign on to the system program create account ix ser ? Commented Jul 23, 2022 at 22:05
  • Yes, that's pretty much it. The PDA's signature will be passed to this program and then onto the system program instruction to create the account.
    – Henry E
    Commented Jul 23, 2022 at 22:07
  • What if this not being called from another program? Can it be done?
    – Trevor
    Commented Jul 24, 2022 at 8:15
0

I need to use a PDA as both a signer and payer in my program. I call a method via cron, and I need the transaction fees to be paid from the PDA account. However, when I try to pay, I receive the following error:

Error updating uptime: Error: Signature verification failed.

Is there any way to automatically deduct the transaction fee from the PDA without requiring the wallet to sign the transaction?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.