const to_writer = ContractPromiseBatch.create(id);
const donationAmount:u128 = context.attachedDeposit;
to_writer.transfer(donationAmount);
In the above code, the near amount extracted from the --amount is transferred from the contract balance.
I can transfer near to the account I want. But I can't transfer near from predecessor balance. Assume I give some service to users and in return, I want to get (receive) some amount near. How can I do that?
I have found the right answer to this question by researching more. There is no need for any additional operation to send near to contract balance from the caller balance. Simply when we call the call methods with the --amount
the attached near automatically is sent to the contract balance. For example:
near call $CONTRACT add '{"url":"http://EXAPMLE.com", "title":"hello world"}' --accountId $AUTHOR --amount 8
Here attached 8 NEAR is sent automatically to the contract balance.