A WebLN interface for creating Bitcoin Lightning powered web applications.

Overview

flutter_webln package logo

A package that helps you to interact with WebLN providers by providing a FlutterWebln interface for creating Bitcoin Lightning powered web applications.


Features

There are methods to:

  • Enable the provider (FlutterWebln.enable)
  • Get information about a users Bitcoin Lightning node (FlutterWebln.getInfo)
  • Send a payment (FlutterWebln.sendPayment)
  • Create an invoice to receive a payment (FlutterWebln.makeInvoice)
  • Request the user to send a keysend payment (FlutterWebln.keysend)
  • Request a signature of an arbitrary message (FlutterWebln.signMessage)
  • Verifies the signature against the raw message (FlutterWebln.verifyMessage)

Getting Started

You first need to install WebLN provider in order to use any of the FlutterWebln methods.

Detecting WebLN support

Before you start using FlutterWebln you need to check for browser support by checking if the variable FlutterWebln.webln is defined:

  void checkWebln() {
    try {
      final weblnValue = weblnDecode(FlutterWebln.webln);
      if (weblnValue.isEmpty) {
        isWallet = false;
      } else {
        isWallet = true;
      }
      print('[+] webln value is $weblnValue');
    } catch (e) {
      print("[!] Error in checkWebln method is $e");
    }
  }

weblnValue.isEmpty indicates that the WebLN provider is not installed and the user can't use any of the FlutterWebln methods.

Enable WebLN

To begin interacting with FlutterWebln methods you'll first need to enable the provider as:

await FlutterWebln.enable()

It will prompt the user for permission to use the WebLN capabilities of the browser. After that you are free to call any of the other FlutterWebln methods.

Get Info

With FlutterWebln.getInfo the user gets information about the connected node as:

 try {
   await FlutterWebln.enable();
   await FlutterWebln.getInfo().then(allowInterop((response) {
     print('[+] GetInfoResponse: ${weblnDecode(response)}');
   }));
 } catch (error) {
   print('[!] Error in getInfo method is $error');
 }

Response

Result: [+] GetInfoResponse: {node: {alias: 🐝 getalby.com}}

Make Invoice

With FlutterWebln.makeInvoice the user creates an invoice to be used by the web app as:

 final invoice = FlutterWebln.requestInvoiceArgs(
   amount: 100,
   defaultMemo: 'Hello World',
 );
 try {
   await FlutterWebln.makeInvoice(requestInvoiceArgs: invoice)
       .then(allowInterop((result) {
     print('[+] RequestInvoiceResponse: ${weblnDecode(result)}');
   }));
 } catch (error) {
   print('[!] Error in makeInvoice method is $error');
 }

Response

[+] RequestInvoiceResponse: {paymentRequest: lnbc1u1p3jdmdzpp5aehslp0ts0wszr62lwl82qwzcgl6jtqudvg000ez75jx307vpcdqdqjfpjkcmr0yptk7unvvscqzpgxqyz5vqsp5npje0n0mct745acshv8dl5pz5kyznz2z6du45fwpyxgwvxvepdts9qyyssqdynz62hf8xh76pn4qfpswzcz4ezt6k9kj9mccf6lzwzkutm04rwjhzynctgphyk6xc0g2ftn7unjxvmszutzr07xq52h5qeja5mk3sqpqwwx7y, rHash: ee6f0f85eb83dd010f4afbbe7501c2c23fa92c1c6b10f7bf22f52468bfcc0e1a}

Send Payment

With FlutterWebln.sendPayment the user sends a payment for an invoice. The user needs to provide a BOLT-11 invoice.

 try {
   await FlutterWebln.sendPayment(invoice: invoiceController.text)
       .then(allowInterop((result) {
     print('[+] SendPaymentResponse: ${weblnDecode(result)}');
   }));
 } catch (error) {
   print('[!] Error in sendPayment method is $error');
 }

Response

[+] SendPaymentResponse: {preimage: 6662313533626135643134626265623164343134363734626261336263306630, paymentHash: ee6f0f85eb83dd010f4afbbe7501c2c23fa92c1c6b10f7bf22f52468bfcc0e1a, route: {total_amt: 100, total_fees: 0}}

Keysend

With FlutterWebln.keysend it request the user to send a keysend payment. This payment only needs a destination public key and amount.

 try {
   await FlutterWebln.keysend(keysendArgs: keysendArgs)
       .then(allowInterop((result) {
     print('[+] KeysendPaymentResponse: ${weblnDecode(result)}');
   }));
 } catch (error) {
   print('[!] Error in keysend method is $error');
 }

Response:

[+] KeysendPaymentResponse: {preimage: 3965373033306134316666323562396262333332393463653136383634636265, paymentHash: 20594ee7899bee252917bc44ec744309d0593adf0e79469bb067afb67b632ffc, route: {total_amt: 20, total_fees: 0}}

Sign Message

With ``FlutterWebln.signMessage` it request that the user signs an arbitrary string message.

 try {
   await FlutterWebln.signMessage(message: 'Hello World!')
       .then(allowInterop((result) {
     print('[+] SignMessageResponse: ${weblnDecode(result)}');
   }));
 } catch (error) {
   print('[!] Error in signMessage method is $error');
 }

Signed messages can either be verified server-side using the LND RPC method, or by clients with FlutterWebln.verifyMessage.

Verify Message

With FlutterWebln.verifyMessage the users's client verifies the signature against the raw message, and let's the user know if it was valid.

 try {
   await FlutterWebln.verifyMessage(
           signature: signatureController.text,
           message: messageController.text,
      ).then(allowInterop((result) {
    print('[+] VerifyMessageResponse: ${weblnDecode(result)}');
   }));
 } catch (error) {
   print('[!] Error in verifyMessage method is $error');
 }

Example Project

flutter_webln package example

The above flutter_webln_integration project can be found here

Reference

You might also like...

NetcastsOSS - Podcasts (netcasts) consumer app powered by open source software, by Flutter

NetcastsOSS - Podcasts (netcasts) consumer app powered by open source software, by Flutter

Netcasts OSS Simple podcasts (netcasts) management powered by open source software Homepage Drawer Explore Discover Podcast Episodes Player Settings W

Sep 16, 2022

A simple log catch server powered by flutter.

flutter_logcat A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

Jan 9, 2022

MQuote provides you +700 Motivational & Inspirational quotes by famous authors, celebrities. Powered by Flutter

MQuote provides you +700 Motivational & Inspirational quotes by famous authors, celebrities. Powered by Flutter

MQuote MQuote provides you +700 Motivational & Inspirational quotes by famous authors, celebrities. you can select your favorite quotes, you can share

Jan 27, 2022

A note-taking app powered by Google services such as Google Sign In, Google Drive, and Firebase ML Vision.

A note-taking app powered by Google services such as Google Sign In, Google Drive, and Firebase ML Vision.

Smart Notes A note-taking app powered by Google services such as Google Sign In, Google Drive, and Firebase ML Vision. This is an official entry to Fl

Oct 26, 2022

This is a simple client of Reddit built with MVVM and Provider powered by a custom OAuth2.0 login

👷 🔧 🔩 Flutter Starter Architecture (MVVM + Hive) My custom starter project for Flutter apps. I was looking for a simple way to build Flutter app in

Oct 26, 2022

Weibo@Flow - A third party Weibo client for Android with Material You theming (iOS version later). 💪 Powered by Flutter 💪

Weibo@Flow - A third party Weibo client for Android with Material You theming (iOS version later).  💪 Powered by Flutter 💪

Weibo@Flow - A third party Weibo client for Android with Material You theming (iOS version later). 💪 Powered by Flutter 💪

Sep 19, 2022

A new handy and powerful Android phone assistant, powered by Flutter.

A new handy and powerful Android phone assistant, powered by Flutter.

AirController is a powerful, handy, and cross-platform desktop application, it can manage your android phone easily without connecting to a computer.

Jan 3, 2023

Safe is an open source mobile platorm to discretely capture incidents with ease, powered by an SMCE written in native Swift and Kotlin.

Safe is an open source mobile platorm to discretely capture incidents with ease, powered by an SMCE written in native Swift and Kotlin.

Safe A powerful tool for personal and community safety. joinsafe.me » Available for iOS & Android ~ Links will be added once a release is available. ~

Oct 26, 2022

TraWell App - your Smart trawell buddy, Powered by AI

TraWell App - your Smart trawell buddy, Powered by AI

TraWell App your Smart trawell buddy, Powered by AI. View Demo · Report Bug · Request Feature About The Project TraWell comes with a cross platform mo

Dec 16, 2022
Owner
Aniket Ambore
Aniket Ambore
The world needs more Lightning!

10101 (a.k.a TenTenOne) Dependencies This project requires Flutter and Rust. Rust toolchain can be installed via Rustup. In order to setup Flutter (as

ItchySats 15 Dec 31, 2022
Lightning fast, strongly typed network protocol

What is Bolt Bolt is a network protocol written in Dart to send and receive strongly typed data objects. It is designed to be easy to use and to be as

Jochum van der Ploeg 42 Dec 3, 2022
A multi purpose Bitcoin wallet

STACKMATE A multi-purpose Bitcoin Wallet Table of Contents Core Features Getting Started Flutter Development VSCode Explorer Exchange Rates API Updati

Morteza 5 Jan 11, 2022
An application to track bitcoin prices around the world.

![App Brewery Banner](https://github.com/londonappbrewery/Images/blob/master/AppBreweryBanner.png) # Bitcoin Ticker ?? ## Our Goal The object

Aryaman Prakash 1 Jan 7, 2022
A multi-purpose Bitcoin Wallet

A multi-purpose Bitcoin Wallet

Stackmate Network 19 Dec 14, 2022
🌍 Responsive web app powered by Flutter and Dart

Flutter Web App Demo Responsive web app powered by Flutter and Dart. Contents Features Requirements Develop Building with the production JavaScript co

Sasha Prokhorenko 208 Nov 24, 2022
Simple Dart package for creating mailto links in your Flutter apps or web pages

mailto Simple Dart package for creating mailto links in your Flutter and Dart apps The mailto package helps you build mailto links and provides you wi

SMAHO Engineering OSS 21 Jul 8, 2022
Another way to build Flutter applications for mobile, web and desktop using the powerful of MVC Design Pattern.

Karee Another way to build Flutter applications for mobile, web and desktop using the powerful of MVC Design Pattern. + = About Karee Karee is a frame

@LeCode 44 Sep 29, 2022
This is a simple client of Reddit built with MVVM and Provider powered by a custom OAuth2.0 login

?? ?? ?? Flutter Starter Architecture (MVVM + Hive) My custom starter project for Flutter apps. I was looking for a simple way to build Flutter app in

Junior Medehou 13 Oct 26, 2022
Sexy and beautiful wallpapers for your Android-powered device! :black_heart:

BLACK UNICORN WALLPAPERS ?? Sexy and beautiful wallpapers for your Android-powered device! ?? About ?? I've always wanted to write an app that had sex

✭ THE BLACK UNICORN ✭ 6 Jun 13, 2022