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();