1

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 2

2

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.

2
  • I agree but if the bump returned is not the same then I have now way to find the public key. 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 Sep 8, 2022 at 15:35
2
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

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.