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

no-std near-gas

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

7 releases

0.2.5 Nov 1, 2023
0.2.4 Oct 22, 2023
0.2.3 Sep 24, 2023
0.2.2 Jul 18, 2023
0.1.3 Jul 11, 2023

#431 in Magic Beans

Download history 463/week @ 2024-01-13 582/week @ 2024-01-20 493/week @ 2024-01-27 586/week @ 2024-02-03 551/week @ 2024-02-10 612/week @ 2024-02-17 589/week @ 2024-02-24 342/week @ 2024-03-02 460/week @ 2024-03-09 508/week @ 2024-03-16 641/week @ 2024-03-23 694/week @ 2024-03-30 814/week @ 2024-04-06 887/week @ 2024-04-13 857/week @ 2024-04-20 722/week @ 2024-04-27

3,387 downloads per month
Used in 13 crates (4 directly)

MIT/Apache

34KB
660 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–660KB
~14K SLoC