xorion-web3-sdk 2.0.0

X-OS Web3 SDK
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# Xorion Developer Guide


Complete guide for building with and contributing to Xorion.

## Table of Contents


1. [Building from Source]#building-from-source
2. [Running Tests]#running-tests
3. [Creating dApps]#creating-dapps
4. [Contributing Guidelines]#contributing-guidelines
5. [Code Style]#code-style
6. [PR Process]#pr-process

---

## Building from Source


### Prerequisites


**Required:**
- Rust 1.75+ (stable)
- Git
- Node.js 18+ (for some tooling)
- pkg-config (Linux/macOS)
- libssl-dev (Linux)

**Optional:**
- Docker & Docker Compose
- VS Code with rust-analyzer
- cargo-edit, cargo-audit

### Installation


#### Clone Repository


```bash
git clone https://github.com/IDevNation/xorion-web3-os.git
cd xorion-web3-os
```

#### Install Rust Toolchain


```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
rustup default stable
```

#### Install Dependencies


**Ubuntu/Debian:**
```bash
sudo apt update
sudo apt install -y build-essential pkg-config libssl-dev cmake protobuf-compiler
```

**macOS:**
```bash
xcode-select --install
brew install pkg-config openssl cmake protobuf
```

**Windows:**
```powershell
# Install Visual Studio Build Tools with C++ workload

# Install OpenSSL from https://slproweb.com/products/Win32OpenSSL.html

```

#### Build Project


```bash
# Debug build (faster, for development)

cargo build

# Release build (optimized)

cargo build --release

# Build specific crate

cargo build -p xorion-sdk

# Build all examples

cargo build --examples
```

#### Run Examples


```bash
# Run demo example

cargo run --example demo

# Run wallet CLI

cargo run -p xorion-cli

# Run GUI (requires display)

cargo run -p xorion-gui
```

---

## Running Tests


### Run All Tests


```bash
cargo test --workspace
```

### Run Tests for Specific Crate


```bash
cargo test -p xorion-sdk
cargo test -p xorion-zk
cargo test -p xorion-ipfs
```

### Run Specific Test


```bash
cargo test test_wallet_creation
cargo test --test integration_tests
```

### Run Tests with Output


```bash
cargo test -- --nocapture
cargo test -- --show-output
```

### Run Tests with Coverage


Install tarpaulin:
```bash
cargo install cargo-tarpaulin
```

Run coverage:
```bash
cargo tarpaulin --workspace --out Html
```

View `tarpaulin-report.html` in browser.

### Integration Tests


```bash
# Run integration tests only

cargo test --test '*'

# Run with local blockchain

cargo test --features integration
```

### Performance Tests


```bash
# Run benchmarks (requires nightly)

rustup default nightly
cargo bench

# Back to stable

rustup default stable
```

---

## Creating dApps


### Development Environment Setup


1. **Install Xorion SDK**

```bash
cargo add xorion-sdk
cargo add xorion-core  # For WASM dApps
```

2. **Set Up Project**

```bash
# Create new Rust project

cargo new my-dapp
cd my-dapp

# Add dependencies

cargo add xorion-sdk ethers tokio serde serde_json
```

3. **Configure for WASM (if needed)**

```toml
# Cargo.toml

[lib]
crate-type = ["cdylib", "rlib"]

[target.wasm32-unknown-unknown.dependencies]
wasm-bindgen = "0.2"
getrandom = { version = "0.2", features = ["js"] }
```

### Hello World dApp


```rust
use xorion_sdk::{Wallet, EthereumProvider};
use ethers::types::Address;

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize wallet
    let wallet = Wallet::from_mnemonic("your mnemonic phrase here")?;
    
    // Get Ethereum address
    let eth_address = wallet.eth_address().await?;
    println!("My address: {}", eth_address);
    
    // Connect to provider
    let provider = EthereumProvider::new("https://mainnet.infura.io/v3/YOUR_KEY");
    
    // Get balance
    let balance = provider.get_balance(eth_address).await?;
    println!("Balance: {} ETH", ethers::utils::format_ether(balance));
    
    Ok(())
}
```

### WASM dApp Template


```rust
use wasm_bindgen::prelude::*;
use xorion_core::{dapp_main, WalletBridge};

#[dapp_main]

struct MyApp {
    bridge: WalletBridge,
}

impl MyApp {
    pub async fn get_balance(&self) -> JsValue {
        let address = self.bridge.get_eth_address().await;
        let balance = self.bridge.get_balance(address).await;
        JsValue::from_str(&balance.to_string())
    }
    
    pub async fn send_transaction(&self, to: String, amount: u64) -> JsValue {
        match self.bridge.send_eth(to, amount).await {
            Ok(tx_hash) => JsValue::from_str(&tx_hash),
            Err(e) => JsValue::from_str(&format!("Error: {}", e)),
        }
    }
}
```

### dApp Permissions


Define required permissions in `dapp.toml`:

```toml
[dapp]
name = "My DApp"
version = "1.0.0"

[permissions]
wallet_access = true
transaction_signing = true
ipfs_storage = true
network_access = ["ethereum", "solana"]
filesystem_read = false
filesystem_write = false
```

### Deploy to IPFS


```bash
# Build for production

cargo build --release --target wasm32-unknown-unknown

# Upload to IPFS

xorion ipfs add target/wasm32-unknown-unknown/release/my_dapp.wasm

# Pin for persistence

xorion ipfs pin <CID>
```

### Testing dApps


```rust
#[cfg(test)]

mod tests {
    use super::*;
    use xorion_sdk::test_utils::*;
    
    #[tokio::test]
    async fn test_get_balance() {
        let app = MyApp::new_test();
        let balance = app.get_balance().await;
        assert!(balance.as_string().is_some());
    }
}
```

---

## Contributing Guidelines


### Ways to Contribute


- ๐Ÿ› Bug reports and fixes
- โœจ New features
- ๐Ÿ“š Documentation improvements
- ๐ŸŽจ UI/UX enhancements
- ๐Ÿงช Test coverage
- ๐Ÿ”’ Security audits
- ๐ŸŒ Translations

### Getting Started


1. **Fork the repository**
2. **Clone your fork**
   ```bash
   git clone https://github.com/YOUR_USERNAME/xorion-web3-os.git

   cd xorion-web3-os

   ```
3. **Create branch**
   ```bash
   git checkout -b feature/your-feature-name

   ```
4. **Make changes**
5. **Test thoroughly**
6. **Submit PR**

### Issue Labels


- `good first issue`: Perfect for newcomers
- `help wanted`: Need community assistance
- `bug`: Something isn't working
- `enhancement`: New feature request
- `documentation`: Docs improvements
- `security`: Security-related

---

## Code Style


### Rust Code Style


We follow standard Rust conventions with rustfmt:

```bash
# Format code

cargo fmt

# Check formatting

cargo fmt -- --check
```

**Key Guidelines:**

- Use `snake_case` for functions and variables
- Use `PascalCase` for types and structs
- Use `SCREAMING_SNAKE_CASE` for constants
- 4-space indentation
- Max line length: 100 characters
- Document public APIs with rustdoc

Example:
```rust
/// Creates a new wallet from mnemonic phrase.
/// 
/// # Arguments
/// * `mnemonic` - BIP-39 recovery phrase (12-24 words)
/// * `password` - Optional BIP-39 passphrase
/// 
/// # Returns
/// * `Result<Wallet, WalletError>` - Created wallet or error
/// 
/// # Example
/// ```
/// let wallet = Wallet::from_mnemonic("abandon abandon ...")?;
/// ```
pub fn from_mnemonic(mnemonic: &str, password: Option<&str>) -> Result<Wallet, WalletError> {
    // Implementation
}
```

### Clippy Linting


```bash
# Run linter

cargo clippy --workspace -- -D warnings

# Auto-fix where possible

cargo clippy --fix --allow-dirty
```

**Common Rules:**
- Avoid `unwrap()` - use `expect()` with message
- Use `if let` instead of `match` for single patterns
- Prefer iterators over indexing
- Use `?` operator for error propagation

### Commit Message Format


We follow Conventional Commits:

```
<type>(<scope>): <subject>

<body>

<footer>
```

**Types:**
- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation
- `style`: Formatting
- `refactor`: Code restructuring
- `test`: Tests
- `chore`: Maintenance

**Example:**
```
feat(wallet): add hardware wallet support

Implemented Ledger Nano S/X integration with full transaction signing.

Closes #123
```

---

## PR Process


### Before Submitting


1. โœ… Code compiles without warnings
2. โœ… All tests pass
3. โœ… Code is formatted
4. โœ… Clippy passes
5. โœ… Documentation updated
6. โœ… Changelog entry added (if applicable)

### Creating Pull Request


1. **Push to your fork**
   ```bash
   git push origin feature/your-feature-name

   ```

2. **Open PR on GitHub**
   - Go to repository
   - Click "New Pull Request"
   - Select your branch
   - Fill out PR template

3. **PR Template**
   ```markdown
   ## Description
   Brief description of changes
   
   ## Type of Change
   - [ ] Bug fix
   - [ ] New feature
   - [ ] Breaking change
   - [ ] Documentation update
   
   ## Testing
   - [ ] Tests added/updated
   - [ ] Manual testing performed
   
   ## Checklist
   - [ ] Code follows style guidelines
   - [ ] Self-review completed
   - [ ] Documentation updated
   - [ ] No new warnings
   ```

### Review Process


1. **Automated Checks**
   - CI builds and tests
   - Security scan
   - Code coverage

2. **Maintainer Review**
   - At least 1 approval required
   - Address review comments
   - Request re-review after changes

3. **Merge**
   - Squash and merge preferred
   - Merge by maintainer only
   - Delete branch after merge

### After Merge


- Monitor for issues
- Help users with questions
- Update documentation if needed

---

## Additional Resources


- **[API Reference]../API.md** - Complete API docs
- **[Architecture]../ARCHITECTURE.md** - System design
- **[Rust Book]https://doc.rust-lang.org/book/** - Learn Rust
- **[Ethers.rs]https://github.com/gakonst/ethers-rs** - Ethereum library
- **[WASM Book]https://rustwasm.github.io/docs/book/** - WebAssembly guide

## Getting Help


- ๐Ÿ’ฌ Discord: #dev channel
- ๐Ÿ“ง Email: dev@xorion.io
- ๐Ÿ› Issues: GitHub Issues
- ๐Ÿ’ก Discussions: GitHub Discussions

---

**Last Updated**: April 2026  
**Version**: 1.0.0

Happy coding! ๐Ÿš€