Created
April 9, 2022 03:14
-
-
Save alecchendev/f03520e05d8dad30b8afb83059ca511c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [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