5

I'm using the REST API of my LN node to generate and pay invoices. I would like to know how to get the invoice amount/value in sats from the payment request I receive.

I found this : https://api.lightning.community/rest/index.html?javascript#v1-invoice, but I don't know how to get the payment hash.

Thanks in advance

1 Answers1

4

I just found the answer : https://api.lightning.community/rest/index.html?javascript#v1-payreq

Use the endpoint v1/payreq to decode the payment request.

Exemple :

var fs = require('fs');
var request = require('request');
var macaroon = fs.readFileSync('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon').toString('hex');
var options = {
  url: 'https://localhost:8080/v1/payreq/{pay_req}',
  // Work-around for self-signed certificates.
  rejectUnauthorized: false,
  json: true, 
  headers: {
    'Grpc-Metadata-macaroon': macaroon,
  },
};
request.get(options, function(error, response, body) {
  console.log(body);
});

And the response :

{ 
    "route_hints": <array RouteHint>, 
    "num_satoshis": <string>, 
    "expiry": <string>, 
    "description_hash": <string>, 
    "timestamp": <string>, 
    "features": <object>, 
    "destination": <string>, 
    "num_msat": <string>, 
    "payment_hash": <string>, 
    "payment_addr": <byte>, 
    "description": <string>, 
    "cltv_expiry": <string>, 
    "fallback_addr": <string>, 
}