I know everything about a PDA, except his public key, is there a way with JS to get the public key of the PDA knowing bump, seeds and programId ?
2 Answers
You can get the PDA account using it seeds and programID, and then check if the obtained bump is the same as the one you have.
You have to use findProgramAddress
method on solana web3 (or anchor too), this will return the PublicKey of the PDA + the bump.
-
I agree but if the bump returned is not the same then I have now way to find the public key. Commented Sep 8, 2022 at 15:33
-
That will be a really weird case, because anchor and Solana will always return the FIRST BUMP, so if your bump is different, then that means that you are using the seed wrongly Commented Sep 8, 2022 at 15:35
const [pda, bump] = await PublicKey.findProgramAddress(
[
publicKey.toBuffer(), <--- public key as seed
Buffer.from('SEED') <--- hardcoded string as seed
],
programId
)
or you can use createProgramAddress and specify the bump seed
https://github.com/solana-labs/solana-web3.js/blob/cd343f7/src/publickey.ts#L191
here's a good article about PDAs and bumps: https://www.sec3.dev/blog/pda-bump-seeds