Search code examples
nearprotocol

Attach deposit in near cli


I want to call transfer function using near cli.

But this command does not work:

near call $ID transfer '{"new_owner_id":"amiyarust.testnet", "amount":50}' --accountId amiyatulu.testnet

"transfer" is a payable method requires an attached deposit.

  #[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);
    }

The near call command gives following error:

panic_msg: "panicked at 'The required attached deposit is 38600000000000000000000, but the given attached deposit is is 0', src/avrit.rs:1026:13"

I already questioned a similar problem here, but unable to find a working solution or code.


Solution

  • If you want to attach deposit to a call, it should be done as a command-line argument, i.e, the call should look like

    near call $ID transfer '{"new_owner_id":"amiyarust.testnet", "amount":50}' --accountId amiyatulu.testnet --amount 50
    

    The amount argument you have in your contract method does not bear any significance in regards to attached tokens.