Any Hive Dapp can accept BTC ⚡️Lightning payments Right NOW!

in HiveDevs2 years ago (edited)

TL;DR - New API makes it TRIVIAL to accept ⚡️Lightning payments as Hive or HBD

API to QR Code to Hive

Full API Documentation here: https://api.v4v.app/docs

As I hinted in my last post, I needed a new API call to make it super easy for Hive Dapp devs to accept ⚡️Lightning and receive Hive.

I did it. The following API call will generate a unique ⚡️Lightning Invoice which can be shown as a QR Code.

curl -X 'GET' \
  'https://api.v4v.app/v1/new_invoice_hive?hive_accname=brianoflondon&amount=3.33&currency=HIVE&usd_hbd=false&app_name=my_hive_dapp&expiry=300&message=180af920-3a58-4a77-9f76-9649a0877926&qr_code=none' \
  -H 'accept: application/json'
https://api.v4v.app/v1/new_invoice_hive?hive_accname=brianoflondon&amount=3.33&currency=HIVE&usd_hbd=false&app_name=my_hive_dapp&expiry=300&message=180af920-3a58-4a77-9f76-9649a0877926&qr_code=none

The API returns:

{
  "r_hash": "1bOdxFlq0dnXHOtFCM5RtXyrfdJdlrzD6ldhR/GsiTg=",
  "payment_hash": "MWJPZHhGbHEwZG5YSE90RkNNNVJ0WHlyZmRKZGxyekQ2bGRoUi9Hc2lUZz0=",
  "payment_addr": "PIZUZP6MeH1EqTTR9pKCFvEW6T5n8do09uNCaYiGHuo=",
  "payment_request": "lnbc70800n1p3d6l9tpp56keem3zedtgan4cuadzs3nj3k472klwjtkttesl22as50udv3yuqd95vfexjctwdanxcmmwv3hkugruyqcnsvrpvcunyvpdxdsn2wpdx3snwded89nrwd3d8ymrgwtpxqurwdeexgmzqlpqyd242j2yypsnjef4v93nqwfdxycxgcfdxsckxe3d89snzefdxycnwdphxy6nvve5xvuzqg6rf3z5zn3qydmrganpwpcqcqzpgxqzfvrzjqv993wr985etnysq5ge5el538egaclg4t2spzmqhvet6futjyem6xz6gmgqqnkcqqyqqqqlgqqqqqqgq9qsp58jr9ge8733u8639fxngldy5zzmc3d6f7vlca5d8kudpxnzyxrm4q9qyyssq5k3ecrzfkjdjfj6wlmtllthj9m562gfthr3r43n3mt58rg3mfqs9h2ag9kqas0nlntj92kg34vet3j6gvcy8z3c23pkz4hayv9f5v7qp7l57fv",
  "amount": 7080,
  "memo": "brianoflondon | 180af920-3a58-4a77-9f76-9649a0877926 | #UUID a9e5ac09-10da-41cf-9a1e-117471563438 #CLEAN #v4vapp",
  "hive_accname": "brianoflondon",
  "app_name": "my_hive_dapp"
}

The field payment_request can be copy pasted into a ⚡️Lightning app, or lightning: can be added to the beginning and turned into a QR Code.

If a user pays that 7080 Sat Invoice with any ⚡️Lightning Wallet app in the next 300 seconds, exactly 3.33 Hive will be transferred to my @brianoflondon Hive account. The memo will be exactly 180af920-3a58-4a77-9f76-9649a0877926

Transaction: 77adfbe8cdea5448f23b3e6e0670e24f576a2b1f
You Got Money!

It's as simple as that.

The API can also return a QR Code as a PNG or base64 encoded png within the JSON response.

There's a GET version:
https://api.v4v.app/docs#/v4vapp/new_invoice_hive_get_v1_new_invoice_hive_get

There's also a couple of POST versions:
https://api.v4v.app/docs#/v4vapp/new_invoice_hive_v1_new_invoice_hive_post
https://api.v4v.app/docs#/v4vapp/new_invoice_hive_qrcode_v1_new_invoice_hive_qrcode_post

Checking Payment status

If your app wants to check payment of the ⚡️Lightning Invoice this is the endpoint for that:

https://api.v4v.app/docs#/v4vapp/check_invoice_v1_check_invoice__payment_hash__get

That API endpoint takes the payment_hash given out by the first call. You can poll that every 15s or so and display a visual representation when the invoice is paid. I do this on v4v.app if you want to see it in use (click on the https://v4v.app/hive tab and you'll see a green tick if you pay a ⚡️Lightning Invoice).

Gateway Status

This simple GET call will give you status and some other useful information:

curl -X 'GET' \
  'https://api.v4v.app/v1' \
  -H 'accept: application/json'

The full typical response is below. Useful points:

  • message should be alive. Anything else and the system isn't working.
  • config.min_max.min and config.min_max.max will give you the sat value limits in Hive, HBD and USD.
{
  "message": "alive",
  "version": "1.13.0",
  "config": {
    "hive_return_fee": 0.002,
    "conv_fee_percent": 0.008,
    "conv_fee_sats": 200,
    "minimum_invoice_payment_sats": 1000,
    "maximum_invoice_payment_sats": 400000,
    "max_acceptable_lnd_fee_msats": 500000,
    "closed_get_lnd": false,
    "closed_get_hive": false,
    "v4v_frontend_iri": "https://v4v.app",
    "v4v_api_iri": "https://api.v4v.app",
    "v4v_fees_streaming_sats_to_hive_percent": 0.03,
    "lightning_rate_limits": [
      {
        "hours": 4,
        "limit": 800000
      },
      {
        "hours": 24,
        "limit": 1600000
      },
      {
        "hours": 72,
        "limit": 2400000
      }
    ],
    "dynamic_fees_url": "@v4vapp/hive-to-lightning-gateway-fees",
    "dynamic_fees_permlink": "hive-to-lightning-gateway-fees",
    "min_max": {
      "min": {
        "conv_from": "sats",
        "sats": 1000,
        "HIVE": 0.598826,
        "HBD": 0.170538,
        "USD": 0.1717
      },
      "max": {
        "conv_from": "sats",
        "sats": 400000,
        "HIVE": 239.530518,
        "HBD": 68.215234,
        "USD": 68.6981
      }
    }
  },
  "onward_response": {
    "state": "SERVER_ACTIVE"
  }
}

Help me tailor this!

I'm somewhat new to creating a public API. If you want this to work a different way, let me know and let's start tailoring this!

Lightning to Sats - dynamic invoice for 1 HBD, sat value recalculated on reload.

Example: Dynamic Invoice for 1 HBD

The invoice to the right is a dynamic invoice. It will be valid for 600s (10 mins) from loading and it will always deliver exactly 1 HBD to me. The correct sat value will be calculated once on loading.

This is the link:

https://api.v4v.app/v1/new_invoice_hive?hive_accname=brianoflondon&amount=1&currency=HBD&usd_hbd=false&app_name=peakd_embed&expiry=600&message=peakd_unique&qr_code=png

Parameters:

amount=1
currency=HBD
app_name=peakd_embed
expiry=600
message=uniquecode
qr_code=png

Support Proposal 222 on PeakD
Support Proposal 222 with Hivesigner
Support Proposal 222 on Ecency


Send Lightning to Me!

Sort:  

A new feature to use for Hive is great. You always keep us updated, thanks a lot !

This is really nice and a work well-done to appreciate, keep up the good work @brianoflondon

@brianoflondon this is awesome! 🔥

Will there be a way to be notified when a payment to me is made? (or can I only stream Hive blocks looking for them and hoping to not skip one?)

If not maybe the API call could accept a URL parameter like:
?done-hook=url-to-call-once-payment-complete.com/api
..and call it appending the block number in which the transfer was made.
So something like https://url-to-call-once-payment-complete.com/api?block=66454068

Just a thought, not sure if it would make sense. May be a good fallback/primary way of reacting to payments in an automated fashion.

Loading...

This is the great thing about Hive.

We have a lot of projects in development, all of them expanding individually. However, nothing operates in a vacuum and the progress of one can often impact the others, some in a large way.

v4v is one of those. The fact that you are going to be able to integrate that into any Hive application is powerful.

Always great to see the amazing progress you are making. This is basic infrastructure stuff that really can help the entire ecosystem.

Posted Using LeoFinance Beta

Great Post!

!1UP

You can earn passive income by delegation of tribe tokens to "The Cartel"!


Click the banner to join "The Cartel" Discord server to know more!


~~~ embed:1551579220358615042 twitter metadata:dGFza21hc3RlcjQ0NTB8fGh0dHBzOi8vdHdpdHRlci5jb20vdGFza21hc3RlcjQ0NTAvc3RhdHVzLzE1NTE1NzkyMjAzNTg2MTUwNDJ8 ~~~
The rewards earned on this comment will go directly to the people( @fragozar01, @taskmaster4450le ) sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.

Great work, the code force is strong with you! 🖖🏼😎🤙🏼

Posted Using LeoFinance Beta

In The Morning ✌️

Great update! Bitcoin/Lightening to Hive is a game changer!

Gold down, oil up.

Funky markets.

Posted Using LeoFinance Beta

1UP-PIZZA.png

You have received a 1UP from @luizeba!

The @oneup-cartel will soon upvote you with:
@leo-curator, @vyb-curator, @pob-curator
And they will bring !PIZZA 🍕.

Learn more about our delegation service to earn daily rewards. Join the Cartel on Discord.

PIZZA!

PIZZA Holders sent $PIZZA tips in this post's comments:
@curation-cartel(17/20) tipped @brianoflondon (x1)

Join us in Discord!

amazing work!

@tipu curate

That's really cool!!!!!!!!

Great, a good way to operate in a flexible manner. Super excited about this development, definitely going to enjoy making payment from https://atomicwallet.io/ multi-coin application.

Interesting, good work. I'm quite sure I will never use it, but if, then I know where to dig for the information. 😁

NICE! That is a really smooth and slick little thing! 😉😎👍

Would love to see a customizable API for HBD and HIVE payments via Lightning for external site use - would be legit!

Posted Using LeoFinance Beta

Read the post again, that's exactly what I've built.

my bad man, misunderstood it. Excellent work! I look forward to integrating such an API into my personal website. I love HIVE & HBD, and being able to accept payments via LN is a game-changer! Kudos!

Posted Using LeoFinance Beta

Just comment here or message me if there's anything you need the API to do or if you need any help getting it working. I really want to see this put to use!

Great post, I'll test it with my BTCLN account. However I really wish there was a **telegram Hive wallet **and maybe a p2p marketplace on telegram.