Skip to content
Izek edited this page Feb 10, 2022 · 1 revision

When you make calls to the NEAR blockchain to update or change data, the people running the infrastructure of the blockchain incur some cost. At the end of the day, some computers somewhere process your request, and the validators running these computers spend significant capital to keep these computers running.

Like other programmable blockchains, NEAR compensates these people by charging transaction fees, also called gas fees.

If you're familiar with web2 cloud service providers (Amazon Web Services, Google Cloud, etc), a big difference with blockchains is that users get charged immediately when they make a call to an app, rather than developers fronting the cost of using all that infrastructure. This creates new possibilities, such as apps that have no long-term risk of going away due to developer/company funds running out. However, it also comes with some usability speed bumps. To help with this, NEAR also provides the ability for developers to cover gas costs for users, to create a more familiar experience to those coming from web2.

When thinking about gas, keep two concepts in mind:

  • Gas units: internally, transaction fees are not calculated directly in NEAR tokens, but instead go through an in-between phase of "gas units". The benefit of gas units is that they are deterministic – the same transaction will always cost the same number of gas units.
  • Gas price: gas units are then multiplied by a gas price to determine how much to charge users. This price is automatically recalculated each block depending on network demand (if previous block is more than half full the price goes up, otherwise it goes down, and it won't change by more than 1% each block), and bottoms out at a price that's configured by the network, currently 100 million yoctoNEAR.

Note that the gas price can differ between NEAR's mainnet & testnet. Check the gas price before relying on the numbers below.

Thinking in gas

​ NEAR has a more-or-less one second block time, accomplished by limiting the amount of gas per block. You can query this value by using the protocol_config RPC endpoint and search for max_gas_burnt under limit_config. The gas units have been carefully calculated to work out to some easy-to-think-in numbers:

  • 10¹² gas units, or 1 TGas (TeraGas)...
  • 1 millisecond of "compute" time
  • ...which, at a minimum gas price of 100 million yoctoNEAR, equals a 0.1 milliNEAR charge

This 1ms is a rough but useful approximation, and is the current goal of how gas units are set within NEAR. Gas units encapsulate not only compute/CPU time but also bandwidth/network time and storage/IO time. Via a governance mechanism, system parameters can be tweaked, shifting the mapping between TGas and milliseconds in the future, but the above is still a good starting point for thinking about what gas units mean and where they come from.

What's the price of gas right now?

​ You can directly query the NEAR platform for the price of gas on a specific block using the RPC method gas_price. This price may change depending on network load. The price is denominated in yoctoNEAR (10^-24 NEAR)

  1. Take any recent block hash from the blockchain using NEAR Explorer. At time of writing, SqNPYxdgspCT3dXK93uVvYZh18yPmekirUaXpoXshHv was the latest block hash

  2. Issue an RPC request for the price of gas on this block using the method gas_price

    http post https://rpc.testnet.near.org jsonrpc=2.0 method=gas_price params:='["SqNPYxdgspCT3dXK93uVvYZh18yPmekirUaXpoXshHv"]' id=dontcare

  3. Observe the results:

    { "id": "dontcare", "jsonrpc": "2.0", "result": { "gas_price": "5000" } }

The price of 1 unit of gas at this block was 5000 yoctoNEAR (10^-24 NEAR).

If you want to learn more about GAS head over to https://docs.near.org/docs/concepts/gas

Astro App

AstroDAO App

Tech Stack

Architecture

Entities

DAOs

Users

Groups

Proposals

Bounties

Treasury

Storage

Processes

Transaction

Voting

Completing a Bounty

Lockup Contracts Delegation

Search

Tips and Tricks

Use Cases

Ecosystem

NEAR

Smart Contract

NEAR CLI

Gas

Bond

Clone this wiki locally