Near Learn

Sending NEAR

Transfer value by creating a Promise. Promise::new(to).transfer(amount) replaces address.call{value:} — and it runs after your method, not during it.

Beginner3 min read3-question check

In Solidity you push value out mid-function with address.call{value: v}(""). On NEAR, sending NEAR is an action: you build a Promise for the recipient, attach a transfer, and (usually) return it. The transfer is scheduled to run *after* your method finishes.

Forward the attached deposit
Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Payout {
    function pay(address payable to) external payable {
        (bool ok, ) = to.call{value: msg.value}("");
        require(ok, "transfer failed");
    }
}
Rust
use near_sdk::{near, env, AccountId, Promise};

#[near(contract_state)]
#[derive(Default)]
pub struct Payout {}

#[near]
impl Payout {
    #[payable]
    pub fn pay(&mut self, to: AccountId) -> Promise {
        let amount = env::attached_deposit();
        Promise::new(to).transfer(amount)
    }
}
Coming from EVM

address.call{value: v}("") / .transfer(v) ↔ Promise::new(to).transfer(amount). The Promise is scheduled when it is dropped at the end of the method, whether you return it or not; returning it makes the transfer’s outcome the method’s result (and lets a caller chain .then(...) on it).

The transfer runs in a separate receipt after your code returns, so there is no re-entrancy *into the middle of* your method — the classic checks-effects-interactions reentrancy bug does not arise the same way. (Callbacks, in the cross-contract chapter, are where you handle the result.)

Amounts are NearToken. env::attached_deposit() is what the caller sent; env::account_balance() is the contract's balance. You cannot send away the NEAR that storage staking locks behind your state.

Check yourself

3 questions · progress saved in this browser

  1. 1.What replaces to.call{value: v}("") for sending NEAR?
  2. 2.When does a NEAR transfer built with Promise::new(to).transfer(amount) actually execute?
  3. 3.Why does the classic Solidity reentrancy bug, where a callee re-enters halfway through your function, not arise the same way on NEAR?