# How to debug eosio::on_notify(“eosio.token::transfer”) actions?

I'm working on a contract that will run an action when receiving tokens. The following code does not run when the account receives EOS or JUNGLE tokens on the Jungle Testnet.

#include "./test.hpp"

...

{
require_auth(_self);
}

void test::ontransfer(name from, name to, asset quantity, string memo)
{
check(true == false, "sorry not sorry");
}

#include <string>

#include <eosio/eosio.hpp>
#include <eosio/asset.hpp>

#define EOS_SYMBOL symbol("EOS", 4)

CONTRACT test : public eosio::contract
{
using contract::contract;

public:
struct init
{
init(){};
eosio::name name;
EOSLIB_SERIALIZE(init, (name))
};

[[eosio::on_notify("eosio.token::transfer")]]
void ontransfer(eosio::name from, eosio::name to, eosio::asset quantity, std::string memo);

// https://eosio.stackexchange.com/questions/4381/why-is-eosioon-notifyeosio-tokentransfer-not-working
using transfer_action = eosio::action_wrapper<eosio::name("transfer"), &test::ontransfer>;

};

EOSIO_DISPATCH(test, (init))


How can I debug this? Is this a problem of v1.6.1? Is there something wrong with my code?

• Does this code work on the main net? – Matei Radu Jun 11 '19 at 11:56
• I have not tested in mainnet yet, that would be useful. I reverted back to the old way of doing it, by defining the apply function. It would be useful as to why this code doesn't work on at least jungle. – marijn Jun 12 '19 at 8:36
• With CDT 1.6.1, the on_notify attribute does not work when you explicitly use EOSIO_DISPATCH, so try to remove the dispatcher as it is no longer mandatory with CDT 1.6. – Matei Radu Jun 12 '19 at 10:07

Using the EOSIO_DISPATCH macros disables the automatic inclusion of actions and on_notifys, and assumes that you will deal with them manually.

To fix this, you have to remove the EOSIO_DISPATCH macro from your header file.

An additional note, as of eosio.cdt 1.6 there is a bug when using on_notify with a wildcard for the contract name, this can be fixed with a hack where a on_notify is added with a given contract name. For example:

Replace:

[[eosio::on_notify("*::transfer")]] void ontransfer(eosio::name from, eosio::name to, eosio::asset quantity, std::string memo);


with:

[[eosio::on_notify("*::transfer")]] void ontransfer(eosio::name from, eosio::name to, eosio::asset quantity, std::string memo);
[[eosio::on_notify("eosio.token::transfer")]] void dummytansfer(eosio::name from, eosio::name to, eosio::asset quantity, std::string memo){ontransfer(from,to,quantity,memo);} // This is a hack, otherwise the ontransfer function won't work