Crate novax

source ·
Expand description

§NovaX Crate

novax is a Rust crate dedicated to generating clients at compile time to interact with smart contracts on a blockchain. The crate automatically generates necessary structures and methods from ABIs (Application Binary Interface) to provide a seamless and type-safe way to interact with smart contracts. The crate’s functionality is driven by the environment variable NOVAX_PATH which should point to a directory containing a sub-directory named abis where the ABIs are located.

§Setup

To use novax, set up the environment variable NOVAX_PATH in your .cargo/config.toml file as follows:

[env]
NOVAX_PATH={ value = ".novax", relative = true }

Here, .novax is a folder at the project’s root containing a sub-directory named abis where the ABIs are placed.

§Modules

  • caching: Provides caching strategies to optimize smart contract queries.
  • errors: Centralized module for handling various error types encountered within the novax crate’s operations.
  • transaction: Contains essential structs and types for handling blockchain transactions.
  • code: Facilitates reading and handling of smart contract code.
  • account: Provides structures and functionalities for handling and obtaining account information.

The crate also includes a generated module from a file in the OUT_DIR directory, which contains structures and methods derived from the ABIs.

§Key Features

  • CachingStrategy and CachingNone: Facilitate caching behavior during query operations, defined in the caching module.
  • CallResult and TokenTransfer: Handle transaction responses and token transfers respectively, located in the transaction module.
  • AsBytesValue, FileCode, and DeployData: Essential for handling smart contract code and deployment data, defined in the code module.
  • AccountInfos and from_address function: Assist in obtaining and handling account-related information, found in the account module.
  • Error Handling: Various error types such as CodeError, CachingError, AccountError, and DateError are defined in the errors module to cover different error scenarios.

§Usage

Once the NOVAX_PATH environment variable is set up and the ABIs are placed in the specified directory, the novax crate automatically generates the required client code when the project is built. This generated code can then be used to interact with the smart contracts as per the methods and structures defined in the ABIs.

§Compile-Time Code Generation

The novax crate utilizes Rust’s procedural macro facilities to perform code generation at compile time. This ensures that the generated code is type-safe, efficient, and ready-to-use right out of the box.

Modules§

  • The account module provides structures and functionalities for handling and obtaining account information.
  • The caching module provides caching strategies to optimize smart contract queries.
  • The code module facilitates reading and handling of smart contract code.
  • The data module provides re-exports of functionalities from the novax_data crate.
  • The errors module centralizes various error types encountered within the novax crate’s operations.
  • The executor module provides re-exports of functionalities from the novax_executor crate.
  • The transaction module contains essential structs and types for handling blockchain transactions.
  • The utils module provides some helpers to make the framework working.

Structs§