Money
Sending NEAR
Transfer value by returning a Promise. Promise::new(to).transfer(amount) replaces address.call{value:} — and it runs after your method, not during it.
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 return it. The transfer is scheduled to run *after* your method finishes.
// 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");
}
}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)
}
}address.call{value: v}("") / .transfer(v) ↔ Promise::new(to).transfer(amount). Returning the Promise from the method is what schedules 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.