1

I am developing an EOS dapp game

When the user acts on the contract after Scatter authentication, the logic is to deposit the bet amount from the user to the contract account.

But I get an eosio.code error. Currently being tested on junglenet This is a situation where we connect 'cleos' command to junglenet and grant eosio.code permission to the contract.

We attach various test cases. I am wondering what is wrong with the code.

first permission_level username, active

void fireballgame::bet(uint64_t game_id, name username, asset betting_amount) {
  require_auth(username);
  action(
    permission_level(username, "active"_n),
    "eosio.token"_n,
    "transfer"_n,
    std::make_tuple(username, _self, betting_amount, std::string(""))
  ).send(); 
}

{ "code": 500, "message": "Internal Service Error", "error": { "code": 3090003, "name": "unsatisfied_authorization", "what": "Provided keys, permissions, and delays do not satisfy declared authorizations", "details": [ { "message": "transaction declares authority '{\"actor\":\"onecenttest1\",\"permission\":\"active\"}', but does not have signatures for it under a provided delay of 0 ms, provided permissions [{\"actor\":\"centcontract\",\"permission\":\"eosio.code\"}], provided keys [], and a delay max limit of 3888000000 ms", "file": "authorization_manager.cpp", "line_number": 524, "method": "check_authorization" }, { "message": "pending console output: ", "file": "apply_context.cpp", "line_number": 113, "method": "exec_one" } ] } }

second permission_level _self, eosio.code (contrect name centcontract)

void fireballgame::bet(uint64_t game_id, name username, asset betting_amount) {
  require_auth(username);
  action(
    permission_level(_self, "eosio.code"_n),
    "eosio.token"_n,
    "transfer"_n,
    std::make_tuple(username, _self, betting_amount, std::string(""))
  ).send(); 
}

{ "code": 500, "message": "Internal Service Error", "error": { "code": 3050000, "name": "action_validate_exception", "what": "Action validate exception", "details": [ { "message": "inline action's authorizations include a non-existent permission: {\"actor\":\"centcontract\",\"permission\":\"eosio.code\"}", "file": "apply_context.cpp", "line_number": 278, "method": "execute_inline" }, { "message": "pending console output: ", "file": "apply_context.cpp", "line_number": 113, "method": "exec_one" } ] }

I have obtained 'eosio.code' permission via the cleos command

enter image description here

So I tried the required permission of _self as active

void fireballgame::bet(uint64_t game_id, name username, asset betting_amount) {
  require_auth(username);
  action(
    permission_level(_self, "active"_n),
    "eosio.token"_n,
    "transfer"_n,
    std::make_tuple(username, _self, betting_amount, std::string(""))
  ).send(); 
}

{ "code": 500, "message": "Internal Service Error", "error": { "code": 3090004, "name": "missing_auth_exception", "what": "Missing required authority", "details": [ { "message": "missing authority of onecenttest1", "file": "apply_context.cpp", "line_number": 201, "method": "require_authorization" }, { "message": "pending console output: ", "file": "apply_context.cpp", "line_number": 113, "method": "exec_one" } ] } }

..?? The user (onecenttest1) is not authorized again

I wonder if I am using the wrong contract

please answer about my question

1 Answer 1

2

Your action "bet" provoke two authorities if you use "username" account other than contract account.

permission_level(_self, "active"_n),

Here in this line, action caller must have authority of contract account and on the other hand authority of that username.

bet(uint64_t game_id, name username, asset betting_amount)

If you modify permission_level as:

permission_level(username, "active"_n),

In that way, user account must have eosio.code permission for your contract but user would not let you do that because in that way, contract will have authority over user account.

So, the most suitable way is to let user have to transfer token to your contract through eosio.token then through notify, you can store the state of user transfer then allow user to perform bet action based on transfer state.

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.