I want to extend the Hello contract (as an exercise)

How do i execute "hi" action when notified by eosio.token contract of an EOS transfer ?

I understood i have to extend EOSIO_ABI macro to handle eosio.token transfer notification, but i cannot get it working.

Thank you

  • 1
    Maybe you could edit your post to include the code you have written, then we will find your error easily. – Phillip Hamnett - EOS42 Sep 10 at 14:55
  • 1
    Did you provide the permission of eosio.code to your contract? you are using eosio.hpp as a header file so first you have to provide the permission of eosio.code to your contract, as Philip said it would be better if you share code. – Nirdesh Kumar Choudhary Sep 11 at 4:13

I finally found a way by redefining EOSIO_ABI.

The "transfer" function in my contract get called when an EOS transfer is done through eosio.token contract.

#undef EOSIO_ABI
extern "C" { \
  void apply( uint64_t receiver, uint64_t code, uint64_t action ) { \
     if( action == N(onerror)) { \
     /* onerror is only valid if it is for the "eosio" code account and authorized by "eosio"'s "active permission */ \
     eosio_assert(code == N(eosio), "onerror action's are only valid from the \"eosio\" system account"); \
  } \
  auto self = receiver; \
  if( code == self || code == N(eosio.token) || action == N(onerror) ) { \
     TYPE thiscontract( self ); \
     switch( action ) { \
     } \
     /* does not allow destructor of thiscontract to run: eosio_exit(0); */ \
     } \
  } \

 EOSIO_ABI(ping_contract, (ping) (transfer) )

I used something like this for the permission:

cleos set account permission CONTRACT_ACCOUNT active '{"threshold": 1,"keys": [{"key":"CONTRACT_ACCOUNT_PUBKEY","weight":1}],"accounts": [{"permission":{"actor":"CONTRACT_ACCOUNT","permission":"eosio.code"},"weight":1}]}' owner -p CONTRACT_ACCOUNT@active
  • Actually you don' need to redefine EOSIO_ABI if you provided the permission , all you have to do is to make a new .cpp file and define a action that you want and use the transfer action of eosio.token. Also you have to import <eosiolib/eosio.hpp> – Nirdesh Kumar Choudhary Sep 11 at 8:47

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.