delta_base_sdk/lib.rs
1//! # delta base SDK
2//!
3//! This crate provides the primary interface for building applications on
4//! the delta network, including tools for communication with base layer providers, account
5//! and vault management, transaction processing, and event subscription.
6//!
7//! # Overview
8//!
9//! This SDK provides access to the base layer functionality, allowing applications to:
10//!
11//! * Query account state through [vaults];
12//! * Create and submit [transactions];
13//! * Monitor network events via [event subscriptions](crate::events);
14//! * Track state transitions through [State Diff Lists](crate::sdl); and
15//! * Communicate with base layer via [RPC](crate::rpc).
16//!
17//! # Quick Start
18//!
19//! Most interactions within delta begin with establishing a connection to base
20//! layer via the [`BaseRpcClient`](crate::rpc::BaseRpcClient):
21//!
22//!
23//! ```rust,no_run
24//! use crate::delta_base_sdk::{
25//! crypto,
26//! crypto::Hash256,
27//! rpc::BaseRpcClient,
28//! transactions::builder::TransactionBuilder,
29//! vaults::ReadableNativeBalance,
30//! };
31//! use std::error::Error;
32//!
33//! async fn start() -> Result<(), Box<dyn Error>> {
34//! // Connect to base layer
35//! let client = BaseRpcClient::new("http://localhost:50051").await?;
36//!
37//! // Generate a new keypair for signing transactions
38//! let keypair = crypto::ed25519::PrivKey::generate();
39//! let pub_key = keypair.pub_key();
40//!
41//! // Query vault state
42//! let vault = client.get_base_vault(pub_key.owner()).await?;
43//! println!("Vault balance: {}", vault.balance());
44//! Ok(())
45//! }
46//! ```
47//!
48//! # Other examples
49//!
50//! [This example](../src/submit/submit.rs.html) provides a more extended code sample.
51
52pub mod rpc;
53
54/// Fundamental type definitions used in delta.
55///
56/// This module provides types that are building blocks for all other protocol
57/// components.
58pub mod core {
59 pub use primitives::type_aliases::{
60 Epoch,
61 Nonce,
62 Planck,
63 SdlId,
64 Shard,
65 TxId,
66 };
67}
68
69/// Parsing utilities for common types
70pub mod parse {
71 pub use primitives::parse::*;
72}
73
74pub mod transactions;
75
76pub mod crypto;
77
78/// # delta's Vaults
79///
80/// Vaults are delta's fundamental state containers, uniquely identified by an [Address](primitives::vault::Address).
81/// A vault contains balances, nonces, and optional specialized data like token mints.
82///
83/// # Example
84///
85/// Reading vault data:
86///
87/// ```rust,no_run
88///
89/// # use crate::delta_base_sdk::{
90/// # crypto::ed25519,
91/// # rpc::BaseRpcClient,
92/// # vaults::{Address, ReadableNativeBalance, ReadableShardedVault},
93/// # };
94/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
95/// let client = BaseRpcClient::new("http://localhost:50051").await?;
96/// let address = Address::new(ed25519::PubKey::generate().owner(), 1);
97/// // Get a vault from the network
98/// let vault = client.get_vault(address).await?;
99/// println!("Balance: {}", vault.balance());
100/// # Ok(())
101/// # }
102/// ```
103pub mod vaults {
104 pub use primitives::{
105 diff::types::TokenKind,
106 tokens::{
107 fungible,
108 nft,
109 },
110 type_aliases::TokenId,
111 vault::{
112 base::{
113 NonceIndex,
114 ReadableBaseVault,
115 Vault as BaseVault,
116 WritableBaseVault,
117 },
118 sharded::{
119 ReadableShardedVault,
120 Vault,
121 VaultFormatter,
122 WritableShardedVault,
123 },
124 vault_data_type::VaultDataType,
125 Address,
126 OwnedVault,
127 OwnerId,
128 ReadableNativeBalance,
129 WritableNativeBalance,
130 },
131 };
132}
133
134pub mod events;
135pub mod sdl;
136
137// tokio is used in `examples/submit` but not in the lib
138// This (test-only) import fixes the linter warning `unused_crate_dependencies`
139#[cfg(test)]
140use tokio as _;