Crates.io | ergo-node-interface |
lib.rs | ergo-node-interface |
version | 0.4.1 |
source | src |
created_at | 2020-11-04 10:39:43.374593 |
updated_at | 2023-12-28 08:05:21.203402 |
description | A library which makes interacting with and using an Ergo Node simple for dApp developers. |
homepage | |
repository | https://github.com/ergoplatform/ergo-node-interface-rust |
max_upload_size | |
id | 308573 |
size | 49,776 |
A Rust library which makes interacting with and using an Ergo Node simple.
This crate uses the great ergo-lib (formerly sigma-rust) for parsing the ErgoBox
es from the Ergo Node and other Ergo-related data-types.
Currently supported features include:
100% of all Ergo Node endpoints are not supported in the present version, as the current goal is to focus on making the off-chain dApp developer experience as solid as possible. Full endpoint coverage is indeed a goal for the long-term nonetheless.
The below are the currently implemented modules part of the Ergo Node Interface library.
This module contains the core NodeInterface
struct which is used to interact with an Ergo Node. All endpoints are implemented as methods on the NodeInterface
struct.
let node = NodeInterface::new(api_key, ip, port);
println!("Current height: {}", node.current_block_height());
Furthermore a number of helper methods are implemented as well, such as:
/// A CLI interactive interface for prompting a user to select an address
pub fn select_wallet_address(&self) -> Result<P2PKAddressString>
/// Returns a sorted list of unspent boxes which cover at least the
/// provided value `total` of nanoErgs.
/// Note: This box selection strategy simply uses the largest
/// value holding boxes from the user's wallet first.
pub fn unspent_boxes_with_min_total(&self, total: NanoErg) -> Result<Vec<ErgoBox>>
This module contains the Scan
struct which allows a developer to easily work with UTXO-set scans. Each Scan
is tied to a specific NodeInterface
, which is inspired from the fact that scans are saved on a per-node basis.
The Scan
struct provides you with the ability to easily:
Example using the scanning interface to register a scan to track an Oracle Pool:
let oracle_pool_nft_id = "08b59b14e4fdd60e5952314adbaa8b4e00bc0f0b676872a5224d3bf8591074cd".to_string();
let tracking_rule = object! {
"predicate": "containsAsset",
"assetId": oracle_pool_nft_id,
};
let scan = Scan::register(
&"Oracle Pool Box Scan".to_string(),
tracking_rule,
node,
).unwrap();
This module provides a few helper functions to save/read from a local node-interface.yaml
file which holds the Ergo Node ip/port/api key. This makes it much quicker for a dApp developer to get their dApp running without having to manually implement such logic himself.
Example functions which are available:
/// Create a new `node-interface.config` with the barebones yaml inside
pub fn create_new_local_config_file() -> Result<()>
/// Opens a local `node-interface.yaml` file and uses the
/// data inside to create a `NodeInterface`
pub fn new_interface_from_local_config() -> Result<NodeInterface> {
Documentation can be accessed via running the following command:
cargo doc --open
See CONTRIBUTING