Gas

Making calls to NEAR blockchain that requires computation power will be charged gas fee. These gas fee compensates the people hosting the server (called validators as we seen in the previous section) for their resources provided. This is similar to renting a cloud service, where you pay the cloud service providers for their resources. However, cloud service providers charged monthly after totalling total resources used, while blockchain users get charged immediately.

Though, some users might not want to pay gas fee at the beginning. Example if you developed a decentralized app (dApp) game product, and you want to pay for your user for the beginning, just to give them a head start and let the user decide whether to continue playing the game or not. NEAR allows developers to cover gas costs for users in that situation. These are called prepaid gas, which you can check in the docs (see References).

There are two concepts to keep in mind when thinking in gas:

  • Gas units: transaction fees are not in NEAR token, but gas units. NEAR token is not deterministic (i.e. stable). As of writing, 1 NEAR costs $10.86. During market peak, 1 NEAR was about $20. But gas units is deterministic. The same transaction always cost the same number of gas units.

You should also note that, should the price of NEAR goes up or down a lot, there is a multiplier that will counter against this to ensure that you always pay the same gas price for the transaction. A transaction that cost 2 cents when 1 NEAR = 10 USD won't become 4 cents when 1 NEAR = 20 USD. The multiplier would be halved so that 20 USD times half of multiplier will still give the same gas units, which equals 2 cents. This multiplier is called gas price.

Gas price: The multiplier that gas units are multiplied by to determine how much to charge users. The price is automaticaly recalculated each block depending on network demand, and bottoms out at a price configured by the network, which is 100 million yoctoNEAR.

1 NEAR = \( 10^{24} \) yoctoNEAR (yN).

Learn how to check the gas price by following this link.

Thinking in Gas

NEAR has more-or-less one second block time, accomplished by limiting the amount of gas per block. You can query this value using the protocol_config RPC endpoint and search for max_gas_burnt under limit_config. Let's look at some easy to think numbers:

  • \( 10^{12} \) gas units, or 1 TGas (TeraGas)
  • \( \approx \) 1 millisecond of "compute" time
  • which, at minimum of 100 million yN, equals 0.1 milliNEAR charge.

The above is a rough but useful approximation. Gas units also includes bandwidth and IO time, not just compute. Hence, tweakable parameters allows changing gas price, and the ratio of TGas and milliseconds in the future.

Common actions

Let's give us some starting point values.

OperationTGasfee (mN)fee(Ⓝ)
Create Account0.420.042\( 4.2 \times 10^{-5} \)
Send Funds0.450.045\( 4.5 \times 10^{-5} \)
Stake0.500.050\( 5.0 \times 10^{-5} \)
Add Full Access Key0.420.042\( 4.2 \times 10^{-5} \)
Delete Key0.410.041\( 4.1 \times 10^{-5} \)

More complex actions like function calls, please refer to the docs. In general, there are no mathematics that could calculate that easily, that's why we attached extra gas.

Extra Gas are attached to the function calls and use on "per-basis" for difficult to calculate gas costs function calls. You can attach a certain amount of gas, and see how much it gets burnt. Extra gas that are not used will get refunded, so it's okay to attached much more extra gas than is used.

References

  • https://learnnear.club/what-is-near-protocol/
  • https://docs.near.org/docs/concepts/gas