#gas #near #unit #protocols #u64 #values #ergonomically

no-std unc-gas

a small crate to work with NEAR Gas unit values ergonomically and efficiently (NEAR Protocol)

2 unstable releases

new 0.10.0 May 15, 2024
0.1.0 Mar 6, 2024

#1505 in Parser implementations

Download history 147/week @ 2024-03-06 8/week @ 2024-03-13 14/week @ 2024-03-20 16/week @ 2024-03-27 125/week @ 2024-04-03 28/week @ 2024-04-10 60/week @ 2024-04-17 9/week @ 2024-04-24

115 downloads per month
Used in 7 crates (4 directly)


660 lines


Crates.io (downloads) Docs.rs Rust Version

unc-gas is crate to ergonomically operate with NEAR Protocol gas unit in Rust projects.

The crate includes UncGas type and constructors for converting data as UncGas and as u64 type values.

unc-gas examples

use unc_gas::UncGas;

fn main() {
    let data = "12.657 tgas";

    let unc_gas: UncGas = data.parse().unwrap();

    // Convert the value to the most precise "gas" unit
    assert_eq!(unc_gas.as_gas(), 12657000000000);
    // Convert the value to "gigagas" unit
    assert_eq!(unc_gas.as_ggas(), 12657);
    // Display Gas. It will print: "Here is 12.7 Tgas"
    println!("Here is {}", unc_gas);

    // When `serde` feature is enabled, UncGas can be used in serde-serializable structs.
    // UncGas will be serialized to a gas-precision u64 value encoded as string.
    struct FunctionCallDetails {
        used_gas: UncGas,

    let details = FunctionCallDetails { used_gas: unc_gas };

    assert_eq!(serde_json::to_string(&details).unwrap(), r#"{"used_gas":"12657000000000"}"#);

UncGas information

On every transaction you send to the network NEAR charges you a fee (aka gas fee). This fee is used to indirectly pay the people that keep the network infrastructure, and to incentivize developers of smart contracts. For more information.

Gas usage in Near Protocol

Crate Features


This project is licensed under the MIT license and Apache-2.0 license.


~12K SLoC