【发布时间】:2021-03-10 00:26:42
【问题描述】:
文档说:
付款方式。我们可以允许方法接受代币转移 连同函数调用。这样做是为了让合同可以 定义使用时需要支付的代币费用。经过 默认情况下,这些方法是不支付的,如果有人会惊慌 将在调用期间尝试将令牌转移给他们。这是 出于安全原因,以防有人意外转移代币 在函数调用期间。
https://github.com/near/near-sdk-rs
这里的token是不是只指native near tokens?
为什么这个功能必须支付?支付附近的代币用于存储?
/// Transfer `amount` of tokens from the caller of the contract (`predecessor_id`) to
/// `new_owner_id`.
/// Act the same was as `transfer_from` with `owner_id` equal to the caller of the contract
/// (`predecessor_id`).
/// Requirements:
/// * Caller of the method has to attach deposit enough to cover storage difference at the
/// fixed storage price defined in the contract.
#[payable]
pub fn transfer(&mut self, new_owner_id: AccountId, amount: U128) {
// NOTE: New owner's Account ID checked in transfer_from.
// Storage fees are also refunded in transfer_from.
self.transfer_from(env::predecessor_account_id(), new_owner_id, amount);
}
https://github.com/near-examples/FT/blob/master/contracts/rust/src/lib.rs#L211
【问题讨论】:
标签: nearprotocol