7

I know how to declare ,initialize and get,set values in a table .My question is Can we add permission to access the table to a particular user inside our smart contract ?

  • 1
    tables are open to read for anyone without even needing a blockchain account. i think the closest you can do is encrypt data in a table with someone's public key so they can read it only if they have the secret key – confused00 Aug 27 '18 at 12:15
7

You can not forbid reading the data from a smart contracts table, because it is exposed by the RPC interface or CLI.

What you can do to prevent understanding it by 3rd parties, is encrypt your data like @confused00 said.

If you just want to limit access for adding, modyfing or deleting, you can use the scopes of the multi_index and the require_auth method, which will check for the right signatures. This would look something like this:

require_auth(user);
testIndex1 test1(_self, user); // code, scope
// iterate over first index 
for(auto itr = test1.begin(); itr != test1.end() && count!=pLimit;) {
   // delete element and update iterator reference
   itr = test1.erase(itr);
   count++;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.