Transfers & Actions
Smart contracts can perform specific Actions
such as transferring NEAR, or calling other contracts.
An important property of Actions
is that they can be batched together when acting on the same contract. Batched actions act as a unit: they execute in the same receipt, and if any fails, then they all get reverted.
Actions
can be batched only when they act on the same contract. You can batch calling two methods on a contract,
but cannot call two methods on different contracts.
Transfer NEAR Ⓝ
You can send $NEAR from your contract to any other account on the network. The Gas cost for transferring $NEAR is fixed and is based on the protocol's genesis config. Currently, it costs ~0.45 TGas
.
- 🌐 JavaScript
- 🦀 Rust
import { NearBindgen, NearPromise, call } from 'near-sdk-js'
import { AccountId } from 'near-sdk-js/lib/types'
@NearBindgen({})
class Contract{
@call({})
transfer({ to, amount }: { to: AccountId, amount: bigint }) {
return NearPromise.new(to).transfer(amount);
}
}
use near_sdk::{near, AccountId, Promise, NearToken};
#[near(contract_state)]
#[derive(Default)]
pub struct Contract { }
#[near]
impl Contract {
pub fn transfer(&self, to: AccountId, amount: NearToken){
Promise::new(to).transfer(amount);
}
}
The only case where a transfer will fail is if the receiver account does not exist.
Remember that your balance is used to cover for the contract's storage. When sending money, make sure you always leave enough to cover for future storage needs.