1

In solidity, I can use mapping(address=>string) to store a name associated with an address. I am hoping to do the same with the anchor.

1
  • 👋🏻 Welcome to Solana, btw! Aug 16, 2022 at 20:43

1 Answer 1

3

This is one of those fundamental differences between EVM and Solana. In Ethereum, a program typically owns its associated data directly through a mapping. In Solana, a program can be assigned as the owner of an account that contains data. So with that in mind, you'd store your string inside an account that is located at an address that only your program can mutate.

What you're looking for is called a program derived account (or PDA).

Here are some resources to get you started:

  1. https://www.brianfriel.xyz/understanding-program-derived-addresses/
  2. https://solanacookbook.com/core-concepts/pdas.html#interacting-with-pdas

Once you've skimmed over those, you can dive in with these examples:

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.