One can find many examples online of using PDAs like a hashmap structure, i.e. for a one to one relationship. How would I go about this if each of my users can have multiple instances of the same kind of data?

1 Answer 1


It's up to you, of course, but the easiest way would be to include an additional numerical seed in the PDA derivation, ie:

Pubkey::find_program_address(&[b"one-to-many", user_pubkey, &[0]], program_id)

This way, you just need to derive the address, starting with 0, and fetch the account for the resulting address. If no account is found at the address, then you can stop iterating.

You could also have an account that just does accounting at an address like:

Pubkey::find_program_address(&[b"accounting", user_pubkey], program_id)

And the account at that address could tell you how many accounts the user has, or even give you a list of seeds to use.

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.