0

I adapted the hello contract, expanding with require_auth() and added an additional account oliver that should be able to execute the action hashin on behalf of the contract owner doctest1. I adjusted the permission within the account doctest1.

When I try to push action hashin, I get an error:

cleos push action doctest1 hashin '["oliver"]' -p oliver@active

Error 3090004: Missing required authority Ensure that you have the related authority inside your transaction!; If you are currently using 'cleos push action' command, try to add the relevant authority using -p option. Error Details: missing authority of active pending console output:

my contract looks like this:

 #include "../include/doctest1.hpp" 

ACTION doctest1::hi(name nm) {   print_f("Name : %\n", nm); }

ACTION doctest1::check(name nm) {
   print_f("Name : %\n", nm);
   eosio::check(nm == "doctest1"_n, "check name not equal to `doctest1`");
 }

  ACTION doctest1::hashin(std::string h) {
   require_auth(_self);
   print_f("my hash: %", h.c_str());
 }

 EOSIO_DISPATCH(doctest1, (hi)(check)(hashin))

doctest1 account permission:

cleos get account -j doctest1 { "account_name": "doctest1", "head_block_num": 1923524, "head_block_time": "2019-03-15T13:12:15.000", "privileged": false, "last_code_update": "2019-03-15T09:33:07.500", "created": "2019-03-14T15:00:38.000", "ram_quota": -1, "net_weight": -1, "cpu_weight": -1, "net_limit": { "used": -1, "available": -1, "max": -1 }, "cpu_limit": { "used": -1, "available": -1, "max": -1 }, "ram_usage": 61719, "permissions": [{ "perm_name": "active", "parent": "owner", "required_auth": { "threshold": 2, "keys": [{ "key": "EOS6nZrpo4hurCZX88njkM5R2i8dmvjerSMfsMoEhK7yBHApqQSDR", "weight": 2 },{ "key": "EOS7pP22kEX2fmgthMeJLT2uz4nwnw6Zu33qC2Pd6w1p4wnYUswyc", "weight": 2 } ], "accounts": [{ "permission": { "actor": "oliver", "permission": "active" }, "weight": 2 } ], "waits": [] } },{ "perm_name": "owner", "parent": "", "required_auth": { "threshold": 1, "keys": [{ "key": "EOS6nZrpo4hurCZX88njkM5R2i8dmvjerSMfsMoEhK7yBHApqQSDR", "weight": 1 } ], "accounts": [], "waits": [] } } ], "total_resources": null, "self_delegated_bandwidth": null, "refund_request": null, "voter_info": null }

What do I need to adjust so doctest1 account can serve as a group of accounts (growing with accounts that need to execute hashin)?

2 Answers 2

1

If several users need to be able to use this function, but they have to authorize themselves to use it, then you would write your function as follows:

ACTION doctest1::hashin(eosio::name user, std::string h){
  require_auth(user);
  print_f("my hash: %", h.c_str());
}

Then the user would call the function as follows:

cleos push action doctest1 hashin '["oliver","oliver"]' -p oliver@active
7
  • Thanks for the fast reply. In your solution, how do I distinguish accounts that should be able to execute the action from those that shouldn't? How can I build a group of allowed users/account?
    – mikem
    Mar 15, 2019 at 17:49
  • So you would create a multi_index, containing a list of allowed accounts, and then you would use eosio::check to confirm that an account was a part of the multi_index table. You can find more information at eosio.github.io/eosio.cdt/1.5.0 Mar 15, 2019 at 19:05
  • Yes, I could have a table containing account information to check against, but that's rather a workaround isn't it? Imagine you would need a table within each and every contract just to manage access control, that is a huge overhead imo. I would rather have someone explain how I can access the additional permission I have implemented in the doctest1(@active) account and make use of it? Thus geting closer in undestanding the permissioning system in eos. If I'm not able to even understand this small step of require_auth(), how far would I get with custom permissions and require_auth2() ^^
    – mikem
    Mar 15, 2019 at 21:53
  • so the question might be cleare if I ask: why does require_auth(_self); not see, that there are additional entries in the permisssion: doctest1@active ? and in consequence allow accout oliver execute the action.
    – mikem
    Mar 15, 2019 at 21:57
  • In what sense is the account oliver connected to the account doctest1. You say you have adjusted the permission, could you show the code by editing your question which you used to set the new permission. Can you show the result of cleos get account doctest1? The overhead for using tables is not so large and it is standard practise as of right now in the smart contract dev world. Are you suggesting that the active permission on the doctest1 account is multisignature, with a threshold of 1 so that anyone who is on the list can use the account with active permission? Mar 18, 2019 at 5:40
0

you have put the "require_auth(_self);" , that means the action will be only executed by the deployed contract account. The keyword "_self" allow only one account which is the name of the deployed contract account. If u want to push that action with ur oliver account just comment the line "require_auth(_self);"

1
  • Thanks for your reply. That is not far from what I need. How do I make the deploy contract account be a group account? With the cleos set permission ... I know how to add other account to said active permission, what I don't know is, how to make my code aware of those additional accounts included in the active permission of the contract deployment account? That seems somehow very difficult to figure out.
    – mikem
    Mar 16, 2019 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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