Overview
1 TerraGas = 10^12 gas units The library provides both “safe” variants (returnResult types) and “throwable” variants (throw errors) for all functions.
Functions
gas()
Creates a NearGas object from gas units.gas(bigint | number): Amount in gas units
NearGas
Safe variant: safeGas()
teraGas()
Creates a NearGas object from TerraGas.teraGas(string): Amount in TerraGas with up to 12 decimal places
NearGas
Safe variant: safeTeraGas()
nearGas()
Creates a NearGas object from either gas units or TerraGas.args(object): Either{ gas: bigint | number }or{ teraGas: string }
NearGas
Safe variant: safeNearGas()
isNearGas()
Type guard to check if a value is a NearGas object.NearGas Object
TheNearGas object provides the following properties and methods:
Properties
gas(bigint): Amount in gas units (lazy-loaded)teraGas(string): Amount in TerraGas (lazy-loaded)
Methods
add()
Add two gas amounts.safeAdd()
sub()
Subtract gas amounts.safeSub()
gt()
Compare if greater than.safeGt()
lt()
Compare if less than.safeLt()
Type Definitions
See NearGas Types for complete type information.Examples
Basic Usage
Safe Operations
Function Call Action
Common Gas Amounts
Validation
The library validates input:-
Gas values: Must be non-negative bigint or integer number
- Valid:
300000000000000n,300000000000000 - Invalid:
3.5,-100n
- Valid:
-
TerraGas values: Must be valid decimal strings with up to 12 decimal places
- Valid:
"300","300.5","0.000000000001" - Invalid:
".5","300.","1.5555555555555"(too many decimals)
- Valid: