I know that there is a concept called deferred transaction but how can I use this concept in transferring the EOS to another account. The scenario is:

I need to transfer certain amount of coins after a particular delay but as eosio.token account has authority to transfer coins, then how can I make a transfer using my custom contract which will be set by my account, to transfer the coins after a delay?


You need to call the transfer action of eosio.token contract with the appropriate arguments after your preferred delay:

void send(account_name from, account_name to, asset amount, string memo, uint64_t delay) { 
    eosio::transaction t{};
        eosio::permission_level(from, N(active)), // with `from@active` permission
        N(eosio.token), // You're sending this to `eosio.token`
        N(transfer),   // to their `transfer` action
        std::make_tuple(from, to, amount, memo));  // with the appropriate args
    t.delay_sec = delay; // Set the delay
    t.send(eosio::string_to_name(memo.c_str()), from); // Send the transaction with some ID derived from the memo

You'll need to set permissions accordingly

$ cleos set account permission <sender-account> active '{"threshold": 1,"keys": [{"key": "<sender-pubkey>","weight": 1}],"accounts": [{"permission":{"actor":"<contract-account>","permission":"eosio.code"},"weight":1}]}' owner -p <sender-account>
  • 1
    Thanks. Like always, to the rescue ;) . Just a small correction. t.send(eosio::string_to_name(memo.c_str()), amount); this should be t.send(eosio::string_to_name(memo.c_str()), from); Aug 9 '18 at 9:16
  • but get this problem, no type named 'transaction' in namespace 'eosio Sep 3 '18 at 7:54
  • @seaify-Freelancer you need to #include<eosiolib/transaction.hpp> and use eosio::transaction if it's not in your scope. here is a more complete example code-wise
    – confused00
    Sep 3 '18 at 10:45

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.