Posts

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

23 comments·0 reblogs
brianoflondon
77
0 views
·
min-read

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' 

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_posthttps://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!