I saw some contract implement a handler which will be triggered when receiving EOS token via eosio.token::transfer. I tried to have the same transfer handler and change some row of my table. But I have got "cannot modify objects in table of another contract"

I ve checked eosio code that it will try to check if the _code (eosio.token) is equal to the current contract (mycontract).


I wonder how other contracts be able to do that? For example in Knight EOS, it is modifying one of its table in his transfer handler (https://github.com/bada-studio/knights_contract/blob/master/knights/knights.cpp#L532) How does it work without getting the same error?


2 Answers 2


_code in multi_index table isn't the second parameter when initializing your contract class.

contract(name receiver, name code, datastream<const char*> ds) {}

If transfer is forwarded from eosio.token, receiver is your account, but code is eosio.token. In eosio::multi_index(name code, uint64_t scope), code here should pass your account name, not eosio.token.


Without the code, it is difficult to observe what was the reason for the exception.

However, generally speaking, when you emplace or modify the data on the table, it all depends on the authority of entry.

My guess is that you are using a table with the account name as a primary key and when you send token, it fails to modify the table. My guess is this is because the authority of that action is given to erosion.token rather than the original account of transfer. One way to bypass this is to use a different primary key in the table(random int) and emplace or modify an entry.

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.