Gas
NEAR meters gas too, but measured in gas units (Tgas), paid by the caller, and attached explicitly to cross-contract calls.
Beginner3 min read3-question check
Both chains meter execution as gas. The differences: NEAR gas is a unit of compute (1 Tgas = 10¹² gas), its price is far more stable, and when you make a cross-contract call you attach a gas budget to it explicitly rather than forwarding whatever is left.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract GasInfo {
// remaining gas for this call
function remaining() external view returns (uint256) {
return gasleft();
}
}use near_sdk::{near, env};
#[near(contract_state)]
#[derive(Default)]
pub struct GasInfo {}
#[near]
impl GasInfo {
// gas attached to this call, and gas burnt so far (in gas units)
// &mut self: gas context only exists in a change call
pub fn prepaid(&mut self) -> u64 {
env::prepaid_gas().as_gas()
}
pub fn used(&mut self) -> u64 {
env::used_gas().as_gas()
}
}gasleft() ≈ env::prepaid_gas() - env::used_gas(). Gas is a Gas type; Gas::from_tgas(5) builds 5 Tgas and .as_gas() reads the raw units. Like the caller-account functions, these are only available in change calls (transactions), so the methods take &mut self — a free near view call would panic as "prohibited in view".
A function call can attach up to 1 PGas (1,000 Tgas) on current mainnet (max_total_prepaid_gas in the protocol config; it was 300 Tgas for years, and many docs still say so). When you schedule a cross-contract call you carve out part of that budget with .with_static_gas(Gas::from_tgas(n)) — unlike Solidity, the callee does not just inherit the remaining gas.
Fees are paid by the signer in NEAR and are refunded for any unused gas. There is no gasprice auction in the EVM sense — the price is a protocol-set value that moves slowly.
Check yourself
3 questions · progress saved in this browser