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 pubkey = keypair.pub_key();
40//!
41//! // Query vault state
42//! let vault = client.get_base_vault(pubkey.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 Shard,
64 TxId,
65 };
66}
67
68/// Parsing utilities for common types
69pub mod parse {
70 pub use primitives::parse::*;
71}
72
73pub mod transactions;
74
75pub mod crypto;
76
77/// # delta's Vaults
78///
79/// Vaults are delta's fundamental state containers, uniquely identified by an [Address](primitives::vault::Address).
80/// A vault contains balances, nonces, and optional specialized data like token mints.
81///
82/// # Example
83///
84/// Reading vault data:
85///
86/// ```rust,no_run
87///
88/// # use crate::delta_base_sdk::{
89/// # crypto::ed25519,
90/// # rpc::BaseRpcClient,
91/// # vaults::{Address, ReadableNativeBalance, ReadableShardedVault},
92/// # };
93/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
94/// let client = BaseRpcClient::new("http://localhost:50051").await?;
95/// let address = Address::new(ed25519::PubKey::generate().owner(), 1);
96/// // Get a vault from the network
97/// let vault = client.get_vault(address).await?;
98/// println!("Balance: {}", vault.balance());
99/// # Ok(())
100/// # }
101/// ```
102pub mod vaults {
103 pub use primitives::{
104 diff::types::TokenKind,
105 tokens::{
106 fungible,
107 nft,
108 },
109 type_aliases::TokenId,
110 vault::{
111 base::{
112 ReadableBaseVault,
113 Vault as BaseVault,
114 WritableBaseVault,
115 },
116 sharded::{
117 ReadableShardedVault,
118 Vault,
119 VaultFormatter,
120 WritableShardedVault,
121 },
122 vault_data_type::VaultDataType,
123 Address,
124 OwnedVault,
125 OwnerId,
126 ReadableNativeBalance,
127 WritableNativeBalance,
128 },
129 };
130}
131
132pub mod events;
133pub mod sdl;
134
135// tokio is used in `examples/submit` but not in the lib
136// This (test-only) import fixes the linter warning `unused_crate_dependencies`
137#[cfg(test)]
138use tokio as _;