3

If I'm right then to call the event of another contract, I need to configure the permissions (allow the call). For example, I have contract aliceclass:

class aliceclass : public contract
{
  public:
    aliceclass(account_name self) : contract(self){}

    /// @abi action
    void callbobact(){
       //call the Nikita contract method 
       ...
    }
};
EOSIO_ABI(aliceclass, (callbobact))

I have contract bobclass:

class bobclass : public contract
{
  public:
    bobclass(account_name self) : contract(self){}

    /// @abi action
    void bobact(){
        print("Hello world!"); 
    }
};
EOSIO_ABI(bobclass, (bobact))

I create two accounts alice and bob, deploy aliceclass with alice account and bobclass with bob account. When I try to implement callbobact like this:

action(
    permission_level{_self , N(active)},
    N(bob),              
    N(bobact),
    std::make_tuple()
).send();

When I call action callbobact authentication error occurs. How to configure permissions for bob and alice? Do I need to use a multisig for this?

1
  • also sometimes there are problems with functions with no parameters. i would add a param to bobact() and therefore an argument to std::make_tuple() too
    – confused00
    Commented Jul 24, 2018 at 23:33

2 Answers 2

1

The way I do this is as follows:

1. I create a new account:

$ cleos create account eosio caller PUB_KEY PUB_KEY

2. I extend [email protected] permissions under caller@active:

$ cleos set account permission caller active '{"threshold": 1,"keys": [{"key": "<PUB_KEY>","weight": 1}],"accounts": [{"permission":{"actor":"alice","permission":"eosio.code"},"weight":1}]}' owner -p caller

3. I modify the eosio::permission_level{_self , N(active)} initialisation to eosio::permission_level{account, N(active)}

4. I modify callbobact() tocallbobact( account_name account )

5. I call callbobact() with the following:

$ cleos push action alice callbobact '["caller"]' -p caller

6. I pray it works

5
  • cleos set account permission caller active '{"threshold": 1,"keys": [{"key": "<PUB_KEY>","weight": 1}],"accounts": [{"permission":{"actor":"alice","permission":"eosio.code"},"weight":1}]}' owner -p caller ------> ERROR: ExtrasError: [[{"key": "<PUB_KEY>","weight": 1}],"accounts": [{"permission":{"actor":"alice","permission":"eosio.code"},"weight":1}]} owner] set parameters dealing with account permissions
    – niksyrov
    Commented Jul 24, 2018 at 14:31
  • yeah you'd need to replace PUB_KEY with the actual public key
    – confused00
    Commented Jul 24, 2018 at 14:59
  • I did it(I just hide it)
    – niksyrov
    Commented Jul 24, 2018 at 15:44
  • it sounds like a typo somewhere in the command. you shouldn't enclose your PUB_KEY between angle brackets if you're doing this (i.e. PUB_KEY not <PUB_KEY>)
    – confused00
    Commented Jul 24, 2018 at 15:50
  • command seems to work for me. do you have an account alice? this is the command i run on my testnet running EOSIO 1.1 cleos set account permission caller active {"threshold": 1,"keys": [{"key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","weight": 1}],"accounts": [{"permission":{"actor":"alice","permission":"eosio.code"},"weight":1}]} owner -p caller
    – confused00
    Commented Jul 24, 2018 at 18:20
0

Update, according to the latest docs


In the class with the action to be called, add a public action_wrapper, so for the OPs example:

using bob_action = action_wrapper<"bobact"_n, &bobclass::bobact>;

Then, construct and call this action wrapper in the caller class:

bobclass::bob_action _bobact{"bobclass"_n, {get_self(), "active"_n}};
_bobact.send();

In the above code, we created an instance of the action wrapper from bobclass. The first parameter in construction is the name of the contract, the second parameter is the permission being used to call the external action. The first parameter of the permission object is the caller contract name (get_self()), and the second parameter is the name of the permission.

Calling ".send()" on an action wrapper will call the action, and if there are any parameters to the action, you would include them here (".send(param1, param2, etc.);").

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.