What are near gas fees?

Written By: Mr. GasMan

The NEAR network, like many others, operates on a fee system known as gas. These fees are essential to indirectly compensate the validators who uphold the network’s infrastructure and to incentivize the development of smart contracts.

In this comprehensive guide, we will delve into the intricacies of gas on the NEAR network, shedding light on its importance and unique features.

Gas: The Backbone of NEAR Transactions

Gas fees are an integral part of the NEAR ecosystem, as they serve multiple crucial functions:

1.1. Preventing Spam Transactions

Every transaction on the NEAR network incurs a small fee, which acts as a deterrent against spamming the network with frivolous or redundant transactions. This fee ensures that users have a genuine intention behind each action they take on the network.

1.2. Read-Only Methods and Fees

Interestingly, read-only methods, which do not involve changes to the blockchain’s state, do not burden users with fees. Instead, validators absorb the associated costs, making it convenient for users to access information from smart contracts.

1.3. Developer Incentive

One distinctive feature of NEAR is how gas fees are utilized. In transactions involving a contract, 30% of the fee goes to the contract itself, serving as a developer incentive. This mechanism encourages the growth of decentralized applications (dApps) within the NEAR ecosystem.

Free Transactions: A Unique NEAR Feature

NEAR stands out by allowing users to execute read-only methods in smart contracts without requiring a NEAR account or charging any fees. In such cases, validators shoulder the gas costs, promoting accessibility and inclusivity within the network.

Understanding Gas Units and Gas Price

3.1. Gas Units: Deterministic and Consistent

Internally, NEAR calculates transaction fees using gas units, ensuring deterministic costs for specific operations. This means that the same operation will consistently consume the same amount of gas, providing predictability for users.

3.2. Gas Price Dynamics

To determine the actual $NEAR fee for a transaction, the gas used in all operations is multiplied by the gas price. The gas price is not static; it undergoes changes from block to block based on network demand. If a previous block is more than half full, the gas price increases; otherwise, it decreases. This dynamic pricing mechanism ensures that fees remain adaptable to network conditions.

3.3. Gas as Wall Time

Gas units are a representation of computational resources, and 1 TGas (10¹² gas units) roughly equates to 1 millisecond of compute time, using the minimum gas price. While this approximation is useful, it’s essential to note that gas units encompass not only compute time but also network and storage-related activities. Future adjustments to the mapping between TGas and milliseconds may occur through governance mechanisms.

Block Production and Gas Limits

NEAR maintains a maximum gas limit per block to ensure that approximately one block is generated every second. This limit aids in optimizing network efficiency and transaction processing speed.

Gas Costs for Common Actions

To provide users with a clearer understanding of gas costs on the NEAR network, here is a breakdown of the costs for some common actions:

Operation TGas Fee (mN) Fee (Ⓝ)
Create Account 0.42 0.042 4.2⨉10⁻⁵
Send Funds 0.45 0.045 4.5⨉10⁻⁵
Stake 0.50 0.050 5.0⨉10⁻⁵
Add Full Access Key 0.42 0.042 4.2⨉10⁻⁵
Delete Key 0.41 0.041 4.1⨉10⁻⁵

These values serve as a reference point for estimating the cost of various actions within the NEAR network.

Buying Gas on NEAR

In NEAR, users don’t directly purchase gas; instead, they attach tokens to their transactions. This approach differs from some other blockchain networks, like Ethereum, where users can pay a higher gas price to expedite transaction processing.

6.1. Deterministic Gas Costs

Gas costs on NEAR are deterministic, meaning that users cannot pay extra to accelerate transaction processing. For simple operations like transfers, the required gas is automatically calculated and attached to the transaction.

6.2. Function Calls and Gas Attachment

Function calls, which can be more complex, require users to explicitly attach a specific amount of gas to their transactions. The maximum value for prepaid gas is currently 3⨉10¹⁴ gas units (300 Tgas).

Attaching Extra Gas for Refunds

Gas requirements for contract calls can be challenging to predict due to varying method complexities and contract states. Users have the flexibility to attach more tokens than needed to cover the gas cost. Any excess gas tokens are refunded to the user, ensuring efficient resource utilization.

Prepaid Gas for Users

NEAR recognizes the importance of providing an optimal onboarding experience for developers and their users. Developers can facilitate prepaid gas for their users by designing applications that enable first-time users to draw funds directly from an account maintained by the developer. This approach streamlines the onboarding process and encourages user engagement.

8.1. Funding Gas Fees

Developers can fund gas fees for their users by allowing them to use funds from the developer’s account designated exclusively for gas fees on a specific dApp. In this scenario, user identification relies on signers’ keys rather than account names.

8.2. Function Calls and Onboarding

Using function calls, developers can enable new users without accounts to access their dApps and contracts on-chain. This involves creating a new access key for the user on the contract’s account, directing it towards the contract itself. This seamless process allows users to use the web app without requiring a separate wallet.

8.3. Developer Fund Allowances

NEAR Protocol does not impose limitations on the usage of developer funds. Developers can set allowances on access keys corresponding to specific users, creating a functionally-rich ecosystem for dApps.

In conclusion, gas fees on the NEAR network serve as a fundamental mechanism for sustaining network operations and incentivizing development. By understanding the nuances of gas units, gas price dynamics, and the unique features of NEAR’s fee system, users and developers can navigate the network with confidence, enjoying efficient transactions and innovative dApp experiences. As NEAR continues to evolve, gas fees will remain an essential component of its decentralized ecosystem, promoting growth and sustainability.