Skip to content

mayoreee/mini-wallet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mini-wallet

Rust implementation of a minimal Bitcoin wallet

Installation

Add to dependencies in Cargo.toml file

[dependencies]
mini-wallet = { git = "https://github.com/mayoreee/mini-wallet", branch = "master" }

Usage

The wallet features methods for the following:

  • send bitcoin (full operation)
  • send bitcoin (watch-only operation)

Send Bitcoin (full operation)

use mini_wallet::{ Network, Wallet };

fn main() {
    let descriptor = "<Insert descriptor>";
    let change_descriptor = "<Insert change descriptor>";

    let recipient = "<Insert recipient address>"; // transaction recipient address
    let amount = 1_000; // amount in satoshis

    // Create a Wallet
    let wallet = Wallet {
        descriptor: String::from(descriptor),
        change_descriptor: String::from(change_descriptor),
        network: Network::Testnet,
    };

    // Send Bitcoin to recipient
    let txid = wallet.send_btc(recipient, amount).unwrap();

    println!("Transaction ID: {:?}", txid);
}

Send Bitcoin (watch-only operation)

use mini_wallet::{ Network, Wallet };

fn main() {
    let descriptor = "<Insert descriptor>";
    let change_descriptor = "<Insert change descriptor>";

    let recipient = "<Insert recipient address>"; // transaction recipient address
    let amount = 1_000; // amount in satoshis

    // Create a Wallet
    let wallet = Wallet {
        descriptor: String::from(descriptor),
        change_descriptor: String::from(change_descriptor),
        network: Network::Testnet,
    };

    // Create a PSBT
    let psbt = wallet.create_tx(recipient, amount).unwrap();
    println!(psbt);
    
    /**
     *  Note: The PSBT (Partially Signed Bitcoin Transaction) is provided in base64 encoded format.
     *        It is to be signed with an external wallet.
     */

    let psbt_signed = "<Insert the signed PSBT>"

    let txid = wallet.broadcast_tx(psbt_signed).unwrap();

    println!("Transaction ID: {:?}", txid);
}

About

Rust implementation of a minimal Bitcoin wallet

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages