In my contract I have an action which is supposed to allow users to collect the tokens they have accumulated. To do this I use:
void transfer_token(account_name receiver, asset quantity, std::string memo) {
action(
permission_level{_self, N(active)},
N(eosio.token),
N(transfer),
std::make_tuple(_self, receiver, quantity, memo)
).send();
}
But for this to work I have to use the following command for every user:
cleos set account permission <contract> active '{"threshold": 1,"keys": [{"key": <public_key>,"weight": 1}],"accounts": [{"permission":{"actor": <user>,"permission":"active"},"weight":1}]}' owner -p <contract>
My question is:
How can I, using scatter and eosjs, setup the authorization for a user to call an action that transfers tokens from the contract to himself?
edit: I am using scatter on my client, and it has been setup properly, I can use it to transfer tokens to the contract.
edit: Here's the output of using the client to call the action that makes the contract transfer tokens to the user.
{
"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\":\"testacccpico\",\"permission\":\"active\"}', but does not have signatures for it under a provided delay of 0 ms, provided permissions [{\"actor\":\"testacccpico\",\"permission\":\"eosio.code\"}], provided keys [], and a delay max limit of 3888000000 ms",
"file": "authorization_manager.cpp",
"line_number": 413,
"method": "check_authorization"
},
{
"message": "pending console output: ",
"file": "apply_context.cpp",
"line_number": 61,
"method": "exec_one"
}
]
}
}
cleos set account permission <account> active '{"threshold": 1,"keys": [{"key": "<key>","weight": 1}],"accounts": [{"permission":{"actor":"<contract>","permission":"eosio.code"},"weight":1}]}' -p <account>
transaction declares authority '{"actor":"testacccpus1","permission":"active"}', but does not have signatures for it.
cleos set account permission <account> active '{"threshold": 1,"keys": [{"key": "<key>","weight": 1}],"accounts": [{"permission":{"actor":"<contract>","permission":"eosio.code"},"weight":1}]}' owner -p <account>@owner
assuming you have the keys for<account>@owner
authority in your wallet and your wallet is unlocked