如何从调用者的余额转移到合约自己的余额?

How can I transfer near from the caller's balance to the contract's own balance?

const to_writer = ContractPromiseBatch.create(id);
const donationAmount:u128 = context.attachedDeposit;
to_writer.transfer(donationAmount);

上述代码中,从--amount中提取的near amount是从合约余额中转出的。

我可以转账到我想要的账户附近。但我不能从前任余额中转移。假设我为用户提供一些服务,并且在 return 中,我想获得(接收)一些接近的金额。我该怎么做?

我通过更多的研究找到了这个问题的正确答案。不需要任何额外的操作来从调用者余额发送接近合约余额。只要我们用 --amount 调用调用方法,附加的 near 就会自动发送到合约余额。例如:

near call  $CONTRACT add '{"url":"http://EXAPMLE.com", "title":"hello world"}' --accountId $AUTHOR --amount 8

这里附上8个NEAR自动发送到合约余额