Building a Lightning App (Lapp) - Discussion

Thanks @Alko89,

I’ve re-run and the invoice is now created without errors (i.e. with invoice details being displayed in the Terminal).

1 Like

I understand the issue now. Its got todo with having two webservers running on one raspberrypi. So when I shutdown BTCPayServer and run the myapp stuff it works on the local network 192.168.178.234, though still not accessible when I want acces this outside by domain, but this are DNS and routing settings I suppose, an other cup of tea :slight_smile:

HI @Goosie,

I’d be interested in how you get on and any issues/workarounds you find are necessary to get the invoicing project working. I will shortly be setting up a Raspberry Pi to install MyNode BTC (with Bitcoin/Lightning full node and BTCPay Server) and then I’ll also be trying this invoice project connecting to it.

All the best,
Mark

Well I think the most easy way to get a lightning app in the air is just by doing it on a separate site. Because I don’t want this and challenged myself I still would like to know how I could add this in, or added to BTCPayserver. reason I dived into the way BTCPayserver is developed.

I did this by:
Forked BTCPayServer to my own github

Hopefully I come into the modus where I can find the webserver config and find a way to add my own sort of docker image, something like that, will see where I end :slight_smile:

2 Likes

Thank you Alko89. Will let you know,when i try it.

1 Like

Not sure, but does your BTCPaynode use the same port by any chance? You can change port in lightning boilerplate by changing the file ./bin/www, the normalizePort method or by setting an .env file in your project.

1 Like

No checked this. It’s running on 3000, changed this to 3001, tried it again, no luck :slight_smile: frustrated issue :slight_smile:

Do you have any firewall setup on your RPi?

Yess.That could be the case as well. In the meantime I have to put a backup back. One step backwards :slight_smile:

Ok :slight_smile: let me know if it works out

1 Like

Hi @Alko89,

The BTCPay server to create the invoice is no longer working again (same error message as I posted a couple of days ago). It was working this morning but not now :frowning:
Please can you check and get back to me?

All the best
Mark

hmmm, I just checked and it worked for me. I can create the invoice using the app or in the BtcPay UI. Can you try again and send me the error message?

1 Like

Hi @Alko89,

I’ve just tried again, still with the error. Here’s the output I get in the Terminal:

MMB:lightning-app-boilerplate Mark$ npm start

[email protected] start /Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate
node ./bin/www

GET / 304 1698.914 ms - -
GET /favicon.ico 404 34.967 ms - 3398
StatusCodeError: 400 - {“error”:“6/25/2020 4:02:57 PM: Creation of invoice starting\n6/25/2020 4:02:57 PM: BTC_USD: The rating rule is coingecko(BTC_USD)\n6/25/2020 4:02:57 PM: BTC_USD: The evaluated rating rule is 9228.459\n6/25/2020 4:02:57 PM: BTC (Off-Chain): Payment method details creation took 125 milliseconds\n6/25/2020 4:02:57 PM: BTC: Payment method unavailable (Impossible to create lightning invoice (Response status code does not indicate success: 400 (Bad Request).))\n”}
at new StatusCodeError (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request-promise-core/lib/errors.js:32:15)
at Request.plumbing.callback (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request-promise-core/lib/plumbing.js:104:33)
at Request.RP$callback [as _callback] (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request-promise-core/lib/plumbing.js:46:31)
at Request.self.callback (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request/request.js:185:22)
at Request.emit (events.js:315:20)
at Request. (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request/request.js:1161:10)
at Request.emit (events.js:315:20)
at IncomingMessage. (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:421:28)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1221:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
statusCode: 400,
error: {
error: ‘6/25/2020 4:02:57 PM: Creation of invoice starting\n’ +
‘6/25/2020 4:02:57 PM: BTC_USD: The rating rule is coingecko(BTC_USD)\n’ +
‘6/25/2020 4:02:57 PM: BTC_USD: The evaluated rating rule is 9228.459\n’ +
‘6/25/2020 4:02:57 PM: BTC (Off-Chain): Payment method details creation took 125 milliseconds\n’ +
‘6/25/2020 4:02:57 PM: BTC: Payment method unavailable (Impossible to create lightning invoice (Response status code does not indicate success: 400 (Bad Request).))\n’
},
options: {
headers: {
‘Content-Type’: ‘application/json’,
Accept: ‘application/json’,
‘User-Agent’: ‘node-btcpay’,
‘X-Accept-Version’: ‘2.0.0’,
etc
etc … with the output concluding:
_callbackCalled: true,
[Symbol(kCapture)]: false
},
toJSON: [Function: responseToJSON],
caseless: Caseless { dict: [Object] },
body: {
error: ‘6/25/2020 4:02:57 PM: Creation of invoice starting\n’ +
‘6/25/2020 4:02:57 PM: BTC_USD: The rating rule is coingecko(BTC_USD)\n’ +
‘6/25/2020 4:02:57 PM: BTC_USD: The evaluated rating rule is 9228.459\n’ +
‘6/25/2020 4:02:57 PM: BTC (Off-Chain): Payment method details creation took 125 milliseconds\n’ +
‘6/25/2020 4:02:57 PM: BTC: Payment method unavailable (Impossible to create lightning invoice (Response status code does not indicate success: 400 (Bad Request).))\n’
},
[Symbol(kCapture)]: false
}
}
POST /invoice - - ms - -

have you tried creating an invoice on the btcpay website? https://lightning.filipmartinsson.com/invoices
Does it work for you there?

1 Like

HI @Alko89,

Yes, that’s what I’m doing. I’m running the code ala the course to create invoice via https://lightning.filipmartinsson.com. I’ve just tried once more and still get the error.

Here is my invoice.js code (from line 6 that is after initialising the constants BTCPAY_PRIV_KEY and BTCPAY_MERCHANT_KEY). I ran the code this morning (ie. from browser localhost:3000 and that worked) before this afternoon adding an additional single line, i.e. res.render(“invoice”, {invoiceId: invoice.id}) that now no longer works. I’ve just run again with the same error.

// Initialize the client
const btcpay = require('btcpay');
const keypair = btcpay.crypto.load_keypair(new Buffer.from(BTCPAY_PRIV_KEY, 'hex'));
const client = new btcpay.BTCPayClient('https://lightning.filipmartinsson.com', keypair, {merchant: BTCPAY_MERCHANT_KEY});


// get & verify invoice.
router.get('/:id', async function(req, res, next) {

});

// Create invoice
router.post('/', function(req, res, next) {
  var dollarAmount = req.body.amount;
  client.create_invoice({price: dollarAmount, currency: "USD"})
  .then(function(invoice){
    console.log(invoice);
    res.render("invoice", {invoiceId: invoice.id})
  })
  .catch(err => console.log(err));
});


module.exports = router;

I understand. This seems very strange :confused:
I wanted you to try out for sanity check if creating an invoice on the Btcpay website works for you. You can also create invoices there.


I also tried your code and it works. If you can create an invoice on Btcpay site, could you try to create a new Private and Merchant key?

1 Like

Hi @Alko89,

Thanks for your guidance. Yes, creating an invoice directly on the Btcpay website does work. I’ve just created one, and the expired invoice from yesterday morning was created via the invoice.js code. But as already stated it was from yesterday afternoon that the code started to fail to create new invoices (see screenshot below):

I’ll now try to create a new private key and merchant id to see if that solves the problem - I’ll get back to you again once I’ve done this…

All the best
Mark

Hi @Alko89,

Unfortunately, I still get error but now also an error creating directly on btcpay webpage (unlike a few minutes ago)!?

I’ve created knew private key, and merchant id, and updated const for each in invoice.js code. The screen shot below shows the new token created (‘marksToken’, the old one used previously is ‘marks’).

However when I run the code I get the same error messages , see the error output at the end of this post.

I therefore tried to create an invoice directly once more (on btcpay) but now also get an error (even though it worked creating an invoice directly earlier this morning - see my previous post) - see screenshot:

Terminal output upon running the code (accessing localhost:3000 in browser):
MMB:lightning-app-boilerplate Mark$ npm start

[email protected] start /Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate
node ./bin/www

GET / 304 1371.318 ms - -
GET /favicon.ico 404 54.548 ms - 3398
StatusCodeError: 400 - {“error”:“6/26/2020 8:31:49 AM: Creation of invoice starting\n6/26/2020 8:31:49 AM: BTC_USD: The rating rule is coingecko(BTC_USD)\n6/26/2020 8:31:49 AM: BTC_USD: The evaluated rating rule is 9146.07\n6/26/2020 8:31:49 AM: BTC (Off-Chain): Payment method details creation took 26 milliseconds\n6/26/2020 8:31:49 AM: BTC: Payment method unavailable (Impossible to create lightning invoice (Response status code does not indicate success: 400 (Bad Request).))\n”}
at new StatusCodeError (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request-promise-core/lib/errors.js:32:15)
at Request.plumbing.callback (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request-promise-core/lib/plumbing.js:104:33)
at Request.RP$callback [as _callback] (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request-promise-core/lib/plumbing.js:46:31)
at Request.self.callback (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request/request.js:185:22)
at Request.emit (events.js:315:20)
at Request. (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request/request.js:1161:10)
at Request.emit (events.js:315:20)
at IncomingMessage. (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Lightning/LightningApp/lightning-app-boilerplate/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:421:28)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1221:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
statusCode: 400,
error: {
error: ‘6/26/2020 8:31:49 AM: Creation of invoice starting\n’ +
‘6/26/2020 8:31:49 AM: BTC_USD: The rating rule is coingecko(BTC_USD)\n’ +
‘6/26/2020 8:31:49 AM: BTC_USD: The evaluated rating rule is 9146.07\n’ +
‘6/26/2020 8:31:49 AM: BTC (Off-Chain): Payment method details creation took 26 milliseconds\n’ +
‘6/26/2020 8:31:49 AM: BTC: Payment method unavailable (Impossible to create lightning invoice (Response status code does not indicate success: 400 (Bad Request).))\n’
},
etc etc …

Hi @Alko89,

Further to my previous posts this morning: I’ve just tried again and this time could create a new invoice directly on the btcpay website (for $23). And so I quickly reran my code (amount $75) and this time it worked! Have you made any changes over the last few minutes?

And now 15 minutes later it no longer works again - either directly via btcpay nor via the same code:


Mark

Ok, this is beyond weird! No I didn’t make any changes. From the error it appears to be an issue with coingecko API (it is used to calculate the BTC price from USD). I’m also seeing these errors in the logs:

warn: PayServer:      Error while contacting exchange coinaverage: Response status code does not indicate success: 500 (Internal Server Error).
warn: PayServer:      Error while contacting exchange coingecko: Response status code does not indicate success: 500 (Internal Server Error).

Again I’m not getting this issue (just created a bunch of invoices in a loop :stuck_out_tongue: ). But if it still doesn’t work for you, could you try changing the Currency from USD to BTC?

1 Like