您正在查看: Surou 发布的文章

EOS智能合约内部调用EOS币转账功能

1、调用currency::inline_transfer静态方法,方法定义如下:
static void inline_transfer( account_name from, account_name to, extended_asset amount, string memo = string(), permission_name perm = N(active) ) {
     action act( permission_level( from, perm ), amount.contract, N(transfer), transfer{from,to,amount,memo} );
     act.send();
}

解释:from,to分别是转账者,接收者。amount是一种扩展资产结构,结构内contract字段为资产属于那个合约。我们要实现内部调用EOS币转账功能,所以contranct应该设置成 N(eosio.token)

调用方式:

extended_asset amount(100,S(4,EOS));
amount.contranct = N(eosio.token);
cuurency::inline_transfer(from,to,amount);
2、定义action,直接发送。其实currency::inline_transfer也是通过定义action实现的。
action(
      permission_level{ _self, N(active) },
      N(eosio.token), N(transfer),  //调用 eosio.token 的 Transfer 合约
      std::make_tuple(_self, to, quantity, std::string(""))).send();

ERROR: Either --buy-ram or --buy-ram-kbytes with non-zero value is required

执行代码

cleos system newaccount eosio dapp.exec2 EOS7D6Kdkugbg6ACgrGg17yPhDWXDbfHZfVcSmez84ph94NGsf2F6 EOS7D6Kdkugbg6ACgrGg17yPhDWXDbfHZfVcSmez84ph94NGsf2F6  --stake-net '50.00 SYS' --stake-cpu '50.00 SYS'

提示
ERROR: Either --buy-ram or --buy-ram-kbytes with non-zero value is required

在命令行尾部添加 --buy-ram-kbytes 10000

cleos system newaccount eosio dapp.exec2 EOS7D6Kdkugbg6ACgrGg17yPhDWXDbfHZfVcSmez84ph94NGsf2F6 EOS7D6Kdkugbg6ACgrGg17yPhDWXDbfHZfVcSmez84ph94NGsf2F6  --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 10000