DEV Community

NOX Ventures
NOX Ventures

Posted on

Building a Native Rust CLI Wallet for a Blockchain in One Session

The Challenge

RustChain is a blockchain that rewards vintage hardware through its Proof-of-Antiquity consensus. Its wallet was Python-only — requiring a full Python runtime, pip, and venv setup just to manage tokens.

I decided to build a native Rust CLI wallet that compiles to a single binary. No runtime dependencies. No setup. Just download and run.

What I Built

rustchain-wallet — a complete CLI wallet for RustChain.

cargo install rustchain-wallet
Enter fullscreen mode Exit fullscreen mode

Features

  • BIP39 seed phrases — 24-word mnemonic generation and recovery
  • Ed25519 cryptography — interoperable with the Python wallet
  • AES-256-GCM encrypted keystores — matching the Python format exactly
  • Full CLI — create, import, send, receive, export, list

Architecture

The wallet is split into three modules:

crypto.rs — Key Management

Generation uses BIP39 mnemonics → PBKDF2-SHA256 (100K iterations) → Ed25519 keypair:

pub fn generate_keypair_from_new_seed() -> (Mnemonic, SigningKey) {
    let mut entropy = [0u8; 32]; // 256 bits = 24 words
    rand::RngCore::fill_bytes(&mut rand::thread_rng(), &mut entropy);
    let mnemonic = Mnemonic::from_entropy(&entropy).unwrap();
    let keypair = derive_keypair_from_mnemonic(&mnemonic);
    (mnemonic, keypair)
}
Enter fullscreen mode Exit fullscreen mode

Addresses use the format RTC + first 40 chars of SHA256(public_key):

pub fn pubkey_to_address(pubkey: &VerifyingKey) -> String {
    let hash = Sha256::digest(pubkey.as_bytes());
    format!("RTC{}", &hex::encode(hash)[..40])
}
Enter fullscreen mode Exit fullscreen mode

keystore.rs — Encrypted Storage

Keystores are encrypted with AES-256-GCM and stored as JSON files in ~/.rustchain/wallets/. The format matches the Python implementation for full interoperability.

network.rs — RustChain Node Communication

Communicates with RustChain nodes via HTTP/JSON. Handles self-signed certificates (common in private blockchain deployments).

Testing

7 unit tests cover the critical paths:

  • Seed generation → address derivation
  • Seed roundtrip (generate → import → same keys)
  • Hex key import
  • Deterministic address generation
  • Transaction signing (128-char hex signatures)
  • Keystore encrypt/decrypt roundtrip
  • Wrong password rejection
running 7 tests
test crypto::tests::test_sign_transfer ... ok
test crypto::tests::test_hex_key_import ... ok
test crypto::tests::test_generate_and_address ... ok
test crypto::tests::test_seed_roundtrip ... ok
test crypto::tests::test_address_deterministic ... ok
test keystore::tests::test_wrong_password ... ok
test keystore::tests::test_encrypt_decrypt_roundtrip ... ok

test result: ok. 7 passed
Enter fullscreen mode Exit fullscreen mode

Key Crates Used

Purpose Crate
Ed25519 ed25519-dalek
BIP39 bip39
Key derivation pbkdf2 + sha2 + hmac
Encryption aes-gcm
CLI clap
HTTP reqwest (with rustls-tls)
Serialization serde + serde_json

Why Rust for Blockchain Wallets?

  1. Single binary — no Python/pip/venv. Users download one file.
  2. Memory safety — no buffer overflows in crypto code.
  3. Cross-compilation — build for Linux, macOS, Windows, ARM, PowerPC from one codebase.
  4. Performance — Ed25519 signing in microseconds.
  5. crates.io — discoverable by the entire Rust ecosystem.

Links

The bounty was 50-100 RTC. Total development time: about 20 minutes. That's the power of Rust's ecosystem — excellent crates for crypto primitives mean you can focus on the business logic.

Top comments (0)