2

As I understand from the link https://solanacookbook.com/core-concepts/accounts.html#account-model that Data account is owned by a Program, and that Program can only modify the data.

Let's say, I deploy a counter program with id 'xyz...klm', then I create a data account using createAccountWithSeed function signed by account 'abc..lmn' and modify the counter. Now, if I call the same program by the passing the same data account and signing the transaction with a different account 'def..abc', the counter is still changed. I would like that the data account can only be modified by 'abc..lmn'and not any other account. How can I do this?

1 Answer 1

4

This is something a smart contract has to implement itself. If you only want a single pubkey to be the authority of some account and whether its data gets updated, then you need to add a check to your program that the authority has signed the transaction. In anchor that can be done with the Signer<'info> type inside the derive accounts macro.

1
  • Ok, I am not using Anchor :( What I have currently done is - passed the data account and the required account in the accounts list while sending the transaction (in the client). In the program, I checked if the signer's key matches the expected key, if yes then move on. Now, what I would like is to fetch the expected key from a PDA, I guess or somewhere externally. Any thoughts? Oct 10, 2022 at 12:23

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.