My HashMap is not functioning properly on Solana when using a Rust program. Is there an alternative approach to achieving a similar functionality to a HashMap? Essentially, I want to retrieve data associated with each user who has donated SOL. When I paste an address, I want to find out what they have donated.

2 Answers 2


For your application, the "Solana" way would be to create a PDA for each user who has donated when the donation ix runs, e.g:

        seeds = [b"user-data-acc", user.key().as_ref()],
        payer = payer,
        space = SIZE_OF_YOUR_STRUCT
    pub user_data: Account<'info, YourUserDataAcc>,

Now you can store whatever information you want in that struct, like:

pub struct YourUserDataAcc {
    pub some_key: Pubkey,
    pub another_key: Pubkey,
    pub amt: u64,

And now you can always derive and load your struct for some userKey the front end with:

    [Buffer.from("user-data-acc", "utf-8"), userKey.toBuffer()],

Hashmaps aren't supported in Solana. Try using a Btree instead.


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.