Instead of using require_auth('_self') is it possible to specify a single or many users, somthing like



require_auth(["bob", "alice"]);

the rest of the contract is

#include <eosio/eosio.hpp>

In the chat @Ami below provided the below solution....

class [[eosio::contract]] hello : public contract {
    using contract::contract;

      void myactiontwo( name user, std::string day_name) {
        if (user == name("bob") || user == name("alice")) {
          print("Hey, ", user, " today is ", day_name);
        } else {

1 Answer 1


If the user name is equal to "bob" or "alice", make sure they have the keys to sign the transaction.

All other users are not allowed to run this action.

if(user==name("bob") || user==name("alice")){
  print("user must be bob or alice");
  require_auth(_self); // will fail for any account other than the owner of the contract.
  • Ami, I added the rest of the contract above, When compiling this I get the error pointing to the || ... /Users/myname/Documents/contracts/hello/hello.cpp:11:35: error: invalid operands to binary expression ('void' and 'void') require_auth(name("bob")) || require_auth(name("alice")); ~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    – Bill
    Jul 7, 2019 at 7:24
  • Sorry, I may have misguided you. The require_auth does not return a boolean so can't be used with the OR operator ||. What exactly are you trying to test here? Are you asking if bob or alica are trying to call this action?
    – Ami Heines
    Jul 7, 2019 at 8:05
  • No problem, I want to make sure that only bob or alice can view the line that gets printed "Hey, bob today is Monday` when i issue cleos push action hello myactiontwo '["bob", "Monday"]' -p bob@active
    – Bill
    Jul 7, 2019 at 8:09
  • In that case, you need to check if the signing user is equal to name('bob') or name('alice')
    – Ami Heines
    Jul 7, 2019 at 8:14
  • Ah ok, could you help me with the syntax?
    – Bill
    Jul 7, 2019 at 8:15

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.