Avail Rust
Avail Rust is a Rust library for communicating with Avail networks.
In Action
This example uses the Tokio runtime, but you
can use any runtime you like. Your Cargo.toml
file could look like this:
[]
= { = "0.2.1", = false, = ["native", "reqwest"] }
= { = "1.45.0", = ["rt-multi-thread", "macros"] }
[!NOTE] For the WASM environment, replace "native" with "wasm".
And then the code:
use *;
async
You can find this example and similar ones in the example directory.
Feature Flags
The library is designed to use only the necessary dependencies, so by using
default-features = false, features = []
, the library will not compile unless
you choose either the native
or wasm
target.
After that, you are free to choose one or all of the following feature flags:
reqwest
: Sets up a basic RPC client for sending and receiving network data. If you’re unsure what this means, it’s best to add this feature flag to your list.tracing
: Enables logging/tracing, which is useful when dealing with nonce and other transaction-related issues. The logging output can be set to JSON format if needed.subxt
: Provides access to the entire external Subxt library. This can be useful when you need to fetch and manage storage and constants-related data.generated_metadata
: Provides access to all possible extrinsics, events, and other chain-related metadata types. By default, a subset of metadata types is already available, but if necessary, this feature flag gives access to everything. Use this feature with caution—it significantly increases compilation time (by over 10 seconds) and may cause rust-analyzer to stop analyzing your code. If a metadata type isn’t available, it’s best to define it manually, as shown in the custom transaction and custom event examples.
Examples
All existing and new examples can be found here. They cover most basic needs and interactions with the chain. If there is something you need that isn’t covered, let us know—we might add it. :)
Here is an incomplete list of current examples:
- Batching transactions
- Executing transactions in parallel
- Writing your own custom transaction or event
- Dealing with blocks and events
- A full example on how to submit a transaction from start to finish
- Subscribing to block headers, blocks, and justifications
Logging/Tracing
To enable tracing, use the tracing
feature flag and call
Client::enable_tracing(boolean)
in your code, where boolean
is true
or
false
depending on whether you want to enable JSON-format structured logging.
Example:
[]
= { = "0.2.1", = false, = ["native", "reqwest", "tracing"] }
= { = "1.45.0", = ["rt-multi-thread", "macros"] }
use *;
async
After everything is set up run the following command:
RUST_LOG=info
Custom Transactions and Events
Sometimes you need a specific transaction or event type not included in the
default metadata. However, enabling the generated_metadata
feature flag may
greatly increase compile time. In such cases, you can define a custom
transaction or event and use it just like any predefined type. Both are simple
to implement and use.
Create a custom transaction:
use ;
async
Create a custom event:
use *;
async
Getting Help
In the avail-rust
repository, we have many examples showing how to use this
library. If something is missing or unclear, don't hesitate to open a
discussion or reach
out to us on Discord (the link is at
the bottom of the page).
Contribution
Thank you for your interest in improving this project! As we are still adding new features and finalizing existing ones, it would be helpful to first post your idea in the discussions or issues.
Pull requests that only fix grammatical mistakes, resolve cargo clippy warnings, or do not add any substantial value will be closed immediately without feedback.