0

There is a contract B with an action 'create' which uses require_auth( get_self() ). I would like to call that action from another contract A, is that even possible and if so - how?

Contract b has

CONTRACT B : public contract
{
   ACTION create() {
      require_auth( get_self() );
      printf("Hello");
   }
}

A noin-working implementation that channels the B account does not work

CONTRACT A : public contract
{
   ACTION do() {
     action (
         permission_level { "B"_n, "active"_n },
         "B"_n,
         "create"_n,
         std::make_tuple (
            ...
         )
     ).send();
   }
}

cleos

cleos push action A do '{}' -p B@active

Both A@active and B@active have eosio.code permission

Error 3090003: Provided keys, permissions, and delays do not satisfy declared authorizations Ensure that you have the related private keys inside your wallet and your wallet is unlocked. Error Details: transaction declares authority '{"actor":"B","permission":"active"}', but does not have signatures for it under a provided delay of 0 ms, provided permissions [{"actor":"A","permission":"eosio.code"}], provided keys [], and a delay max limit of

0

Any inline action from contract A is executed with A@eosio.code permission. require_auth(get_self()) in contract B means it should be executed with B@active permission.

Your case can be resolved by adding A@eosio.code to B@active, but it means that inline actions from contract A can trigger any other actions with B@active permission. Unless you own both contract A and B, you shouldn't do that.

If A@eosio.code is added to A@active, you can check permission like:

eosio::check(has_auth(get_self()) || has_auth("A"_n), "missing required authority");

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.