Skip to content

Commit f9680a2

Browse files
add demo
1 parent d69bbb6 commit f9680a2

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

demo/DEMO.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# BitcoinDA Rust Client Demo
2+
3+
A concise walkthrough of using the `bitcoin_da_client` Rust library to interact with Syscoin’s Data Availability (DA) layer.
4+
This document is organized so both technical and non-technical audiences can understand the ‘what’, ‘why’, and ‘how’.
5+
6+
---
7+
8+
## Table of Contents
9+
10+
1. [High-Level Summary](#high-level-summary)
11+
2. [Overview (Technical)](#overview-technical)
12+
3. [Why It Matters (Business)](#why-it-matters-business)
13+
4. [Prerequisites](#prerequisites)
14+
5. [Installation](#installation)
15+
6. [Demo Code](#demo-code)
16+
7. [Step-by-Step Explanation](#step-by-step-explanation)
17+
8. [Running the Demo](#running-the-demo)
18+
9. [Next Steps](#next-steps)
19+
10. [License](#license)
20+
11. [Contact](#contact)
21+
22+
---
23+
24+
## High-Level Summary
25+
26+
* **Data Availability (DA) Layer:** Think of DA as a secure warehouse where you store proof that your data exists on the blockchain, without bloating the main ledger.
27+
* **Purpose** Show how easy it is to save and retrieve any small piece of data (a “blob”) on Syscoin’s DA layer, using Rust.
28+
* **Key Benefits for Non-Technical Stakeholders:**
29+
30+
* **Reliability:** Data stored on PoDA (Proof-of-Data-Availability) remains accessible and verifiable.
31+
* **Scalability:** Keeps the main blockchain lean while offloading large or infrequently accessed data.
32+
* **Security:** Data integrity is guaranteed by the underlying blockchain consensus.
33+
34+
---
35+
36+
## Overview (Technical)
37+
38+
`bitcoin_da_client` is a Rust library that provides an ergonomic, async interface to:
39+
40+
* Connect to a Syscoin node via JSON-RPC
41+
* Manage wallets
42+
* Query balances
43+
* Store and retrieve arbitrary data blobs on the DA layer (PoDA)
44+
* Perform raw HTTP GET requests against PoDA endpoints
45+
46+
This demo bundles all core operations into a single `main.rs` example.
47+
48+
---
49+
50+
## Why It Matters (Business)
51+
52+
1. **Off-chain Storage with On-chain Integrity**
53+
Large files, audit logs, or proofs can live off the main chain, while still retaining a tamper-proof anchor on Syscoin.
54+
55+
2. **Cost Efficiency**
56+
On-chain transactions can be expensive and slow for large data. DA lets you pay only for proofs, not full data storage.
57+
58+
3. **Instant Verifiability**
59+
Any stakeholder, auditors, partners, or end users can verify data existence with a simple hash lookup, without running a full node.
60+
61+
---
62+
63+
## Prerequisites
64+
65+
* **Rust & Cargo** installed (rustc ≥ 1.60)
66+
* A **running Syscoin node** with RPC enabled
67+
* Access to a **PoDA gateway** URL (e.g. `http://poda.tanenbaum.io/ for testnet)
68+
69+
---
70+
71+
## Installation
72+
73+
Add to your `Cargo.toml`:
74+
75+
```toml
76+
[dependencies]
77+
bitcoin_da_client = "0.1.1"
78+
tokio = { version = "1", features = ["full"] }
79+
reqwest = "0.12"
80+
serde = "1.0"
81+
serde_json = "1.0"
82+
hex = "0.4"
83+
bitcoincore-rpc = "0.19"
84+
jsonrpc = "0.18"
85+
async-trait = "0.1"
86+
```
87+
88+
---
89+
90+
## Demo Code
91+
92+
Save as `src/main.rs`:
93+
94+
```rust
95+
use syscoin_client::SyscoinClient;
96+
use std::time::Duration;
97+
98+
#[tokio::main]
99+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
100+
// Configuration
101+
let rpc_url = "http://localhost:8332";
102+
let rpc_user = "your_rpc_user";
103+
let rpc_password = "your_rpc_password";
104+
let poda_url = "http://poda.example.com";
105+
106+
// Initialize client
107+
println!("Initializing SyscoinClient...");
108+
let client = SyscoinClient::new(
109+
rpc_url,
110+
rpc_user,
111+
rpc_password,
112+
poda_url,
113+
Some(Duration::from_secs(30)),
114+
)?;
115+
println!("Client ready.\n");
116+
117+
// Wallet management
118+
let wallet_name = "demo_wallet";
119+
println!("Loading wallet \"{}\"...", wallet_name);
120+
client.create_or_load_wallet(wallet_name).await?;
121+
println!("Wallet \"{}\" is active.\n", wallet_name);
122+
123+
// Balance retrieval
124+
println!("Retrieving balance...");
125+
let balance = client.get_balance().await?;
126+
println!("→ Current UTXO balance: {} SYSC\n", balance);
127+
128+
// Blob creation
129+
let payload = b"Hello from the bitcoin_da_client demo!";
130+
println!("Uploading blob of {} bytes...", payload.len());
131+
let version_hash = client.create_blob(payload).await?;
132+
println!("→ Blob stored; version hash = {}\n", version_hash);
133+
134+
// Blob retrieval
135+
println!("Downloading blob for hash {}...", version_hash);
136+
let downloaded = client.get_blob_from_cloud(&version_hash).await?;
137+
println!("→ Downloaded {} bytes: \"{}\"\n",
138+
downloaded.len(),
139+
String::from_utf8_lossy(&downloaded)
140+
);
141+
142+
143+
println!("Demo complete! 🎉");
144+
Ok(())
145+
}
146+
```
147+
148+
---
149+
150+
## Step-by-Step Explanation
151+
152+
1. **Initialization** – Creates a `SyscoinClient` pointing at your RPC node and PoDA gateway with a 30-second timeout.
153+
2. **Wallet Management** – Opens or creates the wallet named "demo\_wallet".
154+
3. **Balance Retrieval** – Returns your UTXO balance in SYSC.
155+
4. **Blob Creation** – Uploads your byte payload and returns a version hash.
156+
5. **Blob Retrieval** – Downloads the exact bytes you uploaded.
157+
158+
---
159+
160+
## Running the Demo
161+
162+
1. Update credentials and PoDA URL in `main.rs`.
163+
2. Ensure your Syscoin node is running with port 18370 opened.
164+
3. From the project directory, run:
165+
166+
```bash
167+
cargo run --release
168+
```
169+
4. Observe the console output for each step.
170+
171+
---
172+
173+
174+
---
175+
176+
## Contact
177+
178+
Maintainer: Abdul ([[email protected]](mailto:[email protected]))
179+
GitHub: [https://github.com/SYS-Labs/bitcoin\_da\_client](https://github.com/SYS-Labs/bitcoin_da_client)

0 commit comments

Comments
 (0)