strike-api

Crates.iostrike-api
lib.rsstrike-api
version0.0.3
sourcesrc
created_at2022-03-02 21:39:59.810955
updated_at2022-03-13 03:59:50.226091
descriptionStrike lightning network API for the Bitcoin network.
homepagehttps://theadventuresofaliceandbob.com/
repositoryhttps://github.com/nmharmon8/strike-api.git
max_upload_size
id542558
size1,596,176
Nathan Harmon (nmharmon8)

documentation

README

Strike Lightning API Interface in Rust (Unofficial)

Rust interface to Strike's excellent Lightning Network API. Easily add lightning tipping or payments to any application.

If you don't have an API key, apply for one Strike. In your application use an email with an existing strike account for quick approval.

Tipping Example

Using Strikes API to tip someone, or even yourself, is very easy.

Full Tipping Example Code

Cargo.toml

[dependencies]
# For this example you must include the tipping feature
strike-api = { version = "0.0.3", features = ["tipping"] }
# Any qrcode generation library
qrcode-generator = {version = "4.1.2"}
# Any multi-threading library
tokio = {version = "1.17.0", features = ["full"]}

main.rs

use strike_api::tipping::{tipping_request};
extern crate qrcode_generator;
use qrcode_generator::{QrCodeEcc};

// Currently I only have a async version of tipping
#[tokio::main]
async fn main() {

    let api_key = "<Your API KEY>";
    //This is the account handle of the account you want to tip. Can be your own account or another account
    let account_handle = "magog";
    //This is the amount you want to tip
    let amount = 1.0;
    //The currency the amount is specified in
    let currency = "USD";
    
    //Call the strike api to get a lightning invoice
    let tipping_quote = tipping_request(
        (api_key, account_handle, amount, currency)
    ).await;

    //Check if the request was successful
    match tipping_quote {
        Ok(quote) => {
            create_qrcode(quote.ln_invoice);
        },
        Err(error) => {
            println!("{:?}", error);
        }
    }
}

fn create_qrcode(ln_invoice : String) {
    //Create a qrcode from the ln_invoice,
    match qrcode_generator::to_png_to_file(ln_invoice.clone(), QrCodeEcc::Low, 1024, "ln_qrcode.png") {
        Ok(_) => {
            println!("QR Code created successfully for invoice: {}", ln_invoice);
        },
        Err(error) => {
            println!("Error creating QR Code: {:?}", error);
        }
    }
}

This result in create a payable Lightning invoice, and a qr code saved to a png.

Commit count: 30

cargo fmt