如何进行自动的延迟EOS转账

transaction 里面有一个 delay_sec 的参数,默认是0,可以通过自定义实现延迟EOS转账。

具体代码可以查看 contracts/eosiolib/transaction.hpp

我们通过写一个新的合约,实现延时转账的 send 功能


void send(account_name from, account_name to, asset amount, string memo, uint64_t delay) {
eosio::transaction t{};
t.actions.emplace_back(
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
}
};

最后需要记得对发送者账户进行权限设置,让该合约有权限进行转账操作。

$ 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>

参考:https://eosio.stackexchange.com/questions/1900/how-to-transfer-eos-after-a-particular-delay