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
    }
};

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

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

$ 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>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值