Let's say contract-A has a couple of actions defined. If access to one of the contract-A's action, say action1(), needs to be controlled on account basis, how to do it?

For example, only few accounts (or account@custom only) should be able to trigger action1().

1 Answer 1


If you want to do it from the smart contract side, use require_auth2:

void contractA::action1() {
   require_auth2(N(account), N(custom));
   // rest of the action

If you want to do it from the user side, use $ cleos set action permission:

$ cleos set action permission <account> <contractA> <action1> <name_of_permission> -p <account>@active
  • Well, from contracts perspective, require_auth2 ensures that the 'account' has 'custom' auth. But any account's owner can create the required custom auth and trigger the required action. So, contract owner couldn't restrict the access in this scenario.
    – K K
    Oct 11, 2018 at 4:09
  • And the command line command, authorises the <account>'s custom permission <name_of_permission>, to trigger the <action1>. This also being controlled by the caller's account and not the contract's account. I'm looking for access control by the contract itself in a flexible way.
    – K K
    Oct 11, 2018 at 4:18
  • require_auth2 as exemplified above ensures that the caller is account so no other account can call it regardless of how they set up permissions. and yes, the second example is meant to be controlled by the user not the contract. it shows 2 different ways to do it depending on requirements
    – confused00
    Oct 11, 2018 at 8:35
  • yes, thats right, require_auth2 ensures the caller is account. But what I'm looking for is, the access should be given to a selected set of accounts while rest of the accounts should be blocked to trigger the contract in a flexible way.
    – K K
    Oct 12, 2018 at 16:51
  • yes, the first parameter of require_auth2() is the specific account... require_auth2(N(alice), N(custom) followed by require_auth2(N(bob), N(custom) would only allow alice@custom and bob@custom assuming {bob, alice} is your set of selected of accounts
    – confused00
    Oct 12, 2018 at 17:01

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.