2

I'm trying to find a PDA address inside the solana instruction like so:

pub fn receive_payload(ctx: Context<Receive>) -> Result<()> {
    //ctx.accounts.lz_receive_nonce.increment()?;

    let (pda, bump) =
        Pubkey::find_program_address(&[b"Acc".as_ref(), &payload_seeds[0]], &id());
    ...
}

But when I try to use it with other accounts passed in through the context, I keep running into lifetime mismatch errors. I tried storing the PDA address in the account struct as well, but that throws an error also, since only AccountInfos, Programs and such are allowed to be stored in the account struct by Anchor.

So is there any other way to make the address live as long as the Context itself?

2
  • Why aren't you just passing it through the validator context like any other account?
    – Ademola
    Aug 26, 2022 at 11:30
  • @Ademola I have to follow a strict convention of what accounts I can have passed in - I am restricted by the protocol I use, so I can't just add new accounts to the accounts struct, but I might be able to put something in remainingaccounts. I still need to figure that out.
    – Reynevan
    Aug 26, 2022 at 15:24

1 Answer 1

1

Simply deriving or hardcoding a public key on-chain is not enough to make it acceptable as an account. Any accounts you need must be passed in from the client-side. In this case the right move would indeed be to pass in the account from remainingaccounts if you don't want to make changes to the validator struct.

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.