3

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

3

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>, 
}
| improve this answer | |
  • 3
    Thanks for posting an answer when you found it. – Anonymous Mar 16 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.