Crates.io | strike-api |
lib.rs | strike-api |
version | 0.0.3 |
source | src |
created_at | 2022-03-02 21:39:59.810955 |
updated_at | 2022-03-13 03:59:50.226091 |
description | Strike lightning network API for the Bitcoin network. |
homepage | https://theadventuresofaliceandbob.com/ |
repository | https://github.com/nmharmon8/strike-api.git |
max_upload_size | |
id | 542558 |
size | 1,596,176 |
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.
Using Strikes API to tip someone, or even yourself, is very easy.
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.