Skip to content

Making Payment Transactions Smart With Structured Metadata

Pavan Joshi edited this page Jul 4, 2022 · 4 revisions

Abstract

Specifications such as Webln bought better solutions to the UX for lightning networks. On top of this, many broad applications such as instant payments via a web browser using Bitcoin Sats (eg. Alby), tippings for content writers, podcasts and streamers (Medium tipping via Alby) and many more came into working. Along with every transaction we can also store additional information in form of metadata which can make specifications such as Webln more broad and applicative in terms of interactivity.

Transaction lists as we know them from our private bank accounts are often a simple list of transactions sorted by date. Each transaction has data like Sender, Receiver, amount, reason and date.

The aim of this project is to extend existing standards such as Webln to enrich transactions with additional information as structured metadata so that transactions containing static data contain more meaningful information giving more interactivity to the transactions.

webln.sendPayment method

Webln SendPayment which takes PaymentRequest parameter holding Bolt11 invoice, we can extend this function to add an extra "optional" parameter named metadata which will hold metadata as a string which can be passed to the Wallets.

sendPayment(paymentRequest: string, metadata?: string): Promise<SendPaymentResponse>;

WeblnProvider attachted by wallets currently image

WeblnProvider attached by wallets after implementation of spec image

Architecture of this spec

1. Extend sendPayment method with optional parameter metadata

sendPayment(paymentRequest: string, metadata?: string): Promise<SendPaymentResponse>;

2. Metadata Format used by the site to provide to the Wallet

Use Schema.org specifications to structure metadata in form of JSON-LD

Developers only need to know JSON and two keywords ( @context and @id ) to use the basic functionality in JSON-LD. Compatibility. A JSON-LD document is always a valid JSON document.

eg.

var Metadata = {};
Metadata = {
          "type": "AudioObject",
          "name": title,
          "creator": artist,
          "image": image         
        }
        
  export var Metadata;

3. How to use Schema.org to structure metadata in JSON-LD format

Go through our documentation for this - Here

4. Doing after-payment actions on metadata after passing it to the wallet

webln.sendPayment(Bolt 11 invoice, Metadata)
          .then(function(r) {
            if(r != undefined){  
            // do after payment actions with the metadata. eg. allowing user to download song after payment is done 
          }
          })
          .catch(function(e) {
            alert("Failed: " + e.message);
            console.log('err pay:', e);
          });
    })
    .catch(function(e) {
      alert("Webln error, check console");
      console.log('err, provider', e);
    });
}

Usecases

To get a better grasp on the project idea I decided to create a simple prototype through which a visitor can play a song if they like they can buy a song. While buying a song during confirmation payment they get to know about the song name, artist, and song image(send as base64 encoded string, decode on Alby side). After successful payment, a song gets downloaded into users' local storage.

Video Link

Prototype Code

Alby with extended webln specification

Clone this wiki locally