6b86b273ff
6b86b273ff

Reputation: 36

How to achieve Solidity's mapping in Solana?

How to achieve the functionality of Solidity's mapping in Solana? What I need is a map with an arbitrary number of entries (it'll be evergrowing).

So how to calculate the rent exemption and how to actually do this? Is it even possible?

I just need 1 account, so 1 global hashmap in a program.

I would be storing keys as integers and values as strings.

Upvotes: 0

Views: 510

Answers (2)

ledgermuminary55
ledgermuminary55

Reputation: 1

In Solana, you can use the account-based storage model with PDAs (Program Derived Addresses) to create a global hashmap. Each key-value pair can be stored in a unique account, with the key serving as part of the PDA seed. To calculate rent exemption, use Solana's get_minimum_balance_for_rent_exemption function based on the serialized data size. For a single global hashmap, manage entries via program logic, serializing/deserializing the keys and values efficiently with libraries like borsh.

Upvotes: 0

Maximilian Schneider
Maximilian Schneider

Reputation: 196

in solana it's more common to use PDAs for this purpose, encode the key inside the seed and use the account data for storing the value.

Upvotes: 3

Related Questions