Skip to content

Instantly share code, notes, and snippets.

@alecchendev
Created April 9, 2022 03:14
Show Gist options
  • Save alecchendev/f03520e05d8dad30b8afb83059ca511c to your computer and use it in GitHub Desktop.
Save alecchendev/f03520e05d8dad30b8afb83059ca511c to your computer and use it in GitHub Desktop.
// [get accounts] - user_ai, pda_ai
// regenerate the PDA
// seed scheme: ["arbitrary_seed", user's key]
let (pda, bump) = Pubkey::find_program_address(
&[
b"arbitrary_seed",
user_ai.key.as_ref(),
],
program_id,
);
// OR if you have bump
let pda = Pubkey::create_program_address(
&[
b"arbitrary_seed",
user_ai.key.as_ref(),
&[bump],
],
program_id,
)?;
// throw error if account key doesn't match
if *pda_ai.key != pda {
return Err(MyError::WrongPDA.into())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment