3 releases

0.0.3 Mar 13, 2022
0.0.2 Mar 13, 2022
0.0.1 Mar 2, 2022

#3 in #lightning-network

Custom license

1.5MB
1.5K SLoC

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.

Dependencies

~0–15MB
~136K SLoC