I want to make an array of public keys that paid/transferred sol to my program, and then read this "State" from the backend and fire transactions to the contract. What would be the best way to do this? I was thinking of creating a struct with a vector inside and setting the owner to be the contract, any help is appreciated

1 Answer 1


So, you would have to at a minimum create a Program Owned Account (up to 10 MB max) or a Program Derived Account (up to 10K max) to store the vector in. This would only be updatable by your program.

The PDA approach is more scalable where each PDA just holds the Pubkey from a growth perspective. But if you don't expect the on chain program to have to deal with the entire set you should be good and let the back-end deal with that.

The back-end can query all program associated accounts and get the listing of all the PDA to 'fire' transactions from.

Additional Edit In your case where you want a pubkey and a string association keep in mind that the larger the vector grows it will increase the CU (compute units) to serialize/deserialize each time you need to modify that.

Compare that with having a PDA per entry and would have a very simple data model:

struct Entry {
    key: Pubkey,
    txt: String

and the generation of the PDA you would use the pubkey and/or string to create the address. This will simplify the operations on it and avoid not only deserializing a dynamic vector but searching for the match on the key to delete it.

Add an instruction for the removal and drain the lamports and zero out the small structure of the target PDA.

  • What would be the growth, max entries, in the vector?
    – Frank C.
    Commented Sep 3, 2022 at 14:41
  • I don't have 50 reputation yet, to comment, hence why I had to write it as an answer. @Frank C. Your solution is way better, but how do I get all PDA's created by my program?
    – george
    Commented Sep 4, 2022 at 10:28
  • You should be able to [request a] merge [of] the accounts using the contact us form, @Georges
    – JNat
    Commented Sep 5, 2022 at 10:00

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.