0

Good Day,

I am working on a contract where for example, If I send 2 ETH to a contract, ( 1 ETH = 2 Cryptokitty tokens ) then that contract is supposed to return me 4 Cryptokitty tokens.

What I Have done so far

So far, I am able to transfer the funds from my account to the contract, but I am unsure how to automatically transfer back X amount of funds to the person who sent the 2 Eth.

This is my code called when a transfer takes place on this account.

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

  //Bunch of other code which was removed for simplicity. 


      });

My question is, when I execute

cleos transfer peter bigger "2 CRYCOIN" "memooo" -p peter@active

How can I make it so that, I automatically transfer something back to Peter's account.

0

You need to construct the action and send it. It depends on if you are using multiple or a single contract and some props. Something like this should work:

[[eosio::on_notify("eosio.token::transfer")]]
  void fundpurchase(name from, name to, asset quantity, std::string memo){
  action(
    permission_level {_self,N(active)},
    N(eosio.token),N(transfer),
    std::make_tuple(_self,N(YOURTOKEN_CONTRACT),asset(quantity.amount*2,symbol_type(S(4,YOURTOKEN))),std::string("some memo"))
   ).send();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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