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

no-std near-gas

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

8 releases

0.3.0 Aug 12, 2024
0.2.7 Aug 12, 2024
0.2.5 Nov 1, 2023
0.2.4 Oct 22, 2023
0.1.3 Jul 11, 2023

#9 in #gas

Download history 1765/week @ 2024-07-29 1367/week @ 2024-08-05 2308/week @ 2024-08-12 965/week @ 2024-08-19 1233/week @ 2024-08-26 1802/week @ 2024-09-02 1546/week @ 2024-09-09 1043/week @ 2024-09-16 1217/week @ 2024-09-23 1019/week @ 2024-09-30 1092/week @ 2024-10-07 1898/week @ 2024-10-14 1468/week @ 2024-10-21 1714/week @ 2024-10-28 1322/week @ 2024-11-04 2016/week @ 2024-11-11

6,586 downloads per month
Used in 18 crates (5 directly)

MIT/Apache

35KB
665 lines

near-gas

Crates.io (downloads) Docs.rs Rust Version

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

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

near-gas examples

use near_gas::NearGas;

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

    let near_gas: NearGas = data.parse().unwrap();

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

    // When `serde` feature is enabled, NearGas can be used in serde-serializable structs.
    // NearGas will be serialized to a gas-precision u64 value encoded as string.
    #[derive(serde::Serialize)]
    struct FunctionCallDetails {
        used_gas: NearGas,
    }

    let details = FunctionCallDetails { used_gas: near_gas };

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

NearGas 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

License

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

Dependencies

~0–590KB
~12K SLoC