Closed FrontierPsychiatrist closed 12 months ago
reposted to telegram
Its safest to do everything in the general handler.
But in the general handler I can't extract the token contract?
Best to jump on telegram and post questions in the developer forum https://t.me/antelopedevs
To add on this, in case anyone finds this in the future: The way to handle different token smart contracts in a wildcard receiver is to use get_code
(deprecated now) resp. get_first_receiver
of eosio::contract
.
CONTRACT example : public eosio::contract {
public:
[[eosio::on_notify("*::transfer")]]
void on_transfer(eosio::name from, eosio::name to, eosio::asset quantity, std::string memo);
}
void example::on_transfer(eosio::name from, eosio::name to, eosio::asset quantity, std::string memo) {
if (to != get_self()) {
// Only handle incoming transfer notifications
return;
}
if (get_first_receiver() == "eosio.token"_n) {
// Got EOS, WAX or whatever - do something with it
} else if (get_first_receiver() == "othertoken"_n) {
// Got some other token - do something with it
}
}
If I have a smart contract that defines two event listeners for transfer notifications - one for all smart contracts and one for eosio.token, is it guaranteed that the more specific one gets matched first?
When receiving a token from
eosio.token
, will alywayson_specific_transfer
be called?