A few days ago I posted about the new API I've released allowing Dapp devs especially on Hive to accept ⚡️Lightning payments in the simplest way I can imagine.
I realise when I post on technical topics like a new API (which stands for Application Programming Interface) I have a mix of audiences reading, some of whom see this as gobbledegook and their eyes glaze over. So this is a bit of a higher level explanation.
What is an API?
An Application Programming Interface is an agreed way in which different computers can talk to each other. One system asks a question, the API returns an answer.
What I released this week is an easy peasy (if you're a developer) way for the other developer's program to ask my program for a ⚡️Lightning Invoice and get it.
What is a ⚡️Lightning Invoice
At it's heart a lightning invoice is just a string of letters and numbers. It looks like this:
lnbc50300n1p3wplg5pp5kwxt0z6jyza2l7k83dj80cgfy4yzhvsn4vkal8qyl96da20c9ftsd9yvfexjctwdanxcmmwv3hkugruypsku7fqd4jhxumpvajjqem0v4ejq6r9wfjjqlpqyd242j2yypnrwe3exsckxwpdxfjnzdfdxscxvved8qur2dfd8ycnzenyxqukydpsvs6zqg6rf3z5zn3qydyyy3pqydmrganpwpcqcqzpgxqzfvrzjqv993wr985etnysq5ge5el538egaclg4t2spzmqhvet6futjyem6xz6gmgqqnkcqqyqqqqlgqqqqqqgq9qsp5jzxvdzqmyck9tuc9pxa4a286d3qp5xwexmh8chv4ddp6zusqem6q9qyyssqvmlr7xju9q6ngu7kvyuwmraw5nteghcu5lsz83wggsvarlr035eph3kw95dxttw0496uqct7v37v9scycjnyyanlwn9llxvtucpvg2gp3tw4zz
And because it looks like that crazy thing on the left, we usually convert them into the now familiar QR Codes. The other Developer using my API will have to show that invoice to their users somehow.
What does my API do?
I give Hive Dapp devs a way to request a ⚡️Lightning Invoice which is valid for up to 10 minutes only. The developer just has to specify a few things:
- The Hive account name where the funds will go if the invoice is paid
- The amount they want in either Hive, HBD or even USD.
- A message to be sent along with the transfer
- The name of the app asking for this invoice (this is mostly for me to keep track of things in the background).
- Expiry time up to 10 mins (600s)
All of that can turn into the following GET
Request which is simply the way the other computer program talks to my API server:
curl -X 'GET' \ 'https://api.v4v.app/v1/new_invoice_hive?hive_accname=brianoflondon&amount=1¤cy=USD&usd_hbd=true&app_name=peakd_demo&expiry=300&message=any%20message%20goes%20here&qr_code=base64%20png' \ -H 'accept: application/json'
Behind the scenes it is the infrastructure which I've built for @v4vapp which will watch to see if that ⚡️Lightning Invoice is paid and, if and when it is, make a transfer of the correct amount of Hive or HBD to the correct account with the correct message.
BTW that message is very important: if you're paying for a basket of goods, the message would allow the other Dapp's computer program to identify exactly which shopping basket was just paid for!
What about the blockchain?
This brings me to the point about blockchains.
When I posted about the API, someone asked if my API server could perhaps send a notification back when the invoice is paid. There are various ways to do this on the old web: I could send an email or use something called a Webhook. This is actually how the legacy credit card payment processors operate.
But this is kind of missing the point of what makes a public blockchain like Hive so powerful and radically different from private closed systems.
I ALREADY do send a message! The Payment IS the message. The Hive Transfer I send arrives within 3s of a Lightning invoice being paid. It contains the correct message and once I've sent it, there's no way I can take it back.
So it would be completely redundant for me to build ANOTHER inferior system for sending a reply just to tell the other program that funds were received. What if my program just faked these? I could easily do that.
The point here is that any Dapp developer working with programmable money on a public blockchain like Hive needs to treat that public blockchain as their source of truth: the only authoritative system where you can learn that a payment has been made.
Slow vs Quick
This is the reason why paying for goods and services with Bitcoin on the main Bitcoin blockchain is not feasible for most things! 10 minutes between blocks and the lottery of which block a transaction will get in, make it way too slow for checkout. We don't have this problem on Hive.
⚡️Lightning has a different issue: Lightning payments are all private. Only the receiver and the sender know that a payment has happened so there is no notion of a public way to check if a payment goes through. This is one of the key functions my Lightning to Hive Bridge performs.
⚡️Lightning payments are very well suited to the web. I firmly believe that it can become a widely used system. However receiving ⚡️Lightning is more challenging. That is why the @v4vapp service over Hive could well become something much bigger than it is today.