Building a Lightning App (Lapp) - Discussion

I would have one question, about redirection of payments that I receive from LSAT(https://medium.com/tierion/lsats-pseudonymous-authentication-using-bitcoin-lightning-payments-459e209b4b36).

Is it possible to create some kind of "smart contract"or else to redirect part of payment that I received to one address and the rest to second address.

I am trying not to be custodian, and not to have manual work with redirecting payments that I receive.

Thank you for your help.

Jaka

Hello sir, I remember long ago i talked with a student something like that, he came up with this solution (still on alpha) for that, an automated way to distribute funds to different address when a payment is receive.

Maybe that can be useful for you too.

Carlos Z.

1 Like

Thank you for your reply. Appreciate it.

1 Like

Hi there, Doing the course steps again;
When I run the command: node -p “require(‘btcpay’).crypto.generate_keypair()”
I get no privatekey anymore. I get a json output like this

What’s the privatekey in this case?

1 Like

Found the solution, the command should be now:

node -p “require(‘btcpay’).crypto.generate_keypair().getPrivate(‘hex’)”

1 Like

I tried to connect to your node but it seems offline. In the meantime I have setup my own node:
02da34389fc11724cf97689b74caffb14a71649b66e10328b1d3e3d0e0495e9270@6tegfxcqk5aitcc2ooebwcooeezezx4enqxk3i5wzn5gcmbikam7c2id.onion:9735

Would appreciate a connection back and I will fund the channel :wink:

Perry

1 Like

Glad to know you find it yourself sir! congratulations! :muscle:

You can also try this command instead, you should be able to get the key with it:

node -p "require('btcpay').crypto.generate_keypair().getPrivate().toString(16)"

I’m sure @Fabrice would like to create a channel with you!

Hope you find this useful! :slight_smile:

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

@Goosie

I have a node running, you can always connect to my node if you wanna play around.

Alias: Zio

0290ba7b9d7d16d86c6ab71b43258f38e6eea12c71da110a2d895c6ae20fcdc01a@y6vk4gqwfbb2dg4m.onion:9735

1 Like

Thanks, I connected you as peer and opened a channel with you, thanks!
Perry

2 Likes

My Node URI is:
02da34389fc11724cf97689b74caffb14a71649b66e10328b1d3e3d0e0495e9270@6tegfxcqk5aitcc2ooebwcooeezezx4enqxk3i5wzn5gcmbikam7c2id.onion:9735

2 Likes

I’ll open a channel back when I’m home :+1:

1 Like

Thanks, seems we have our channel open:-)

2 Likes

Hi

I’m in the ‘Creating Lightning invoices’ section of the course. I’ve added the create_invoice function call, but when I execute (ie. enter an amount and submit via the webpage) I get the error below. I tried about 5 hours ago and thought the BTCPay Server may be down, but trying again just now I get the same error. Any ideas of what might be going wrong?

Here’s my invoice.js code (from the point after I assign my private key and merchant key to the const variables:

// 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);
  })
  .catch(err => console.log(err));
});


module.exports = router;```


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 1688.277 ms - -
GET /favicon.ico 404 71.422 ms - 3398
StatusCodeError: 400 - {“error”:“6/23/2020 6:57:19 PM: Creation of invoice starting\n6/23/2020 6:57:19 PM: BTC_USD: The rating rule is coingecko(BTC_USD)\n6/23/2020 6:57:19 PM: BTC_USD: The evaluated rating rule is 9667.938\n6/23/2020 6:57:19 PM: BTC (Off-Chain): Payment method details creation took 343 milliseconds\n6/23/2020 6:57:19 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/23/2020 6:57:19 PM: Creation of invoice starting\n’ +
‘6/23/2020 6:57:19 PM: BTC_USD: The rating rule is coingecko(BTC_USD)\n’ +
‘6/23/2020 6:57:19 PM: BTC_USD: The evaluated rating rule is 9667.938\n’ +
‘6/23/2020 6:57:19 PM: BTC (Off-Chain): Payment method details creation took 343 milliseconds\n’ +
‘6/23/2020 6:57:19 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

toJSON: [Function: responseToJSON],
caseless: Caseless { dict: [Object] },
body: {
  error: '6/23/2020 6:57:19 PM: Creation of invoice starting\n' +
    '6/23/2020 6:57:19 PM: BTC_USD: The rating rule is coingecko(BTC_USD)\n' +
    '6/23/2020 6:57:19 PM: BTC_USD: The evaluated rating rule is 9667.938\n' +
    '6/23/2020 6:57:19 PM: BTC (Off-Chain): Payment method details creation took 343 milliseconds\n' +
    '6/23/2020 6:57:19 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 - -

when i am adding “type=charge;server=https://api-token:6ba722c01e01846c671fed7a6909bbda8ebedf0b842fd75c9a82220132b34e60@lightning.filipmartinsson.com:443/lightning-charge/btc/” in the field Connection string and press button test connection it says The lightning node is not synched (150 blocks left). is your node synched or am I doing anything wrong?

Second question is. I have my own lightning node. How can i connect btc pay server with it. Where could I get link to enter it in the field Connection string?

Thank you

I’m trying to run just the hello world on a running server which is a raspberrypi which can be accessed by http://btcpay.btcexperiments.com Now when I setup a directory by ssh to this server, git the lighting boilerplate, added my node and merchant keys, I create a welcome message in /views/index.jade and than run npm start. I should now go to localhost:3000 which I do by going to http://btcpay.btcexperiments.com:300 of 192.168.179:300 (my local ip from the raspberry) I get site
can’t be reached. How should I start npm start in this case?

hi @Goosie are you connecting to the right port? You wrote 192.168.179:300 it should be 192.168.179:3000 (port 3000). I have tried connecting to the boilerplate on my desktop from my laptop and it works using my local IP.

1 Like

Hi @Drojc17 :slight_smile: I checked the server and seems to be working fine. I’ll have to investigate a bit further to see what is the issue.

As for connecting your own Lightning node to btcpay you can easily install your own if you want. You can check their documentation to learn how to deploy it on your own server:
https://docs.btcpayserver.org/Deployment/

1 Like

Fixed! :smiley: can you try again and let me know how it goes?

1 Like

hi @MarkSuscens :slight_smile: can you try again? There was an issue with the Lightning node not syncing with Bitcoin.

1 Like

No. I don’t get it working. On my my local ubuntu PC it’s working (localhost:3000 is oke, but as soon I go to my raspberrypi I don’t get it working.
What I do step by step:

  1. From my ubuntu machine i ssh to my local raspberrypi where I have BTCPayServer running on.
    ssh [email protected]
  2. sudo su - to come into the root.
  3. git clone https://github.com/filipmartinsson/lightning-app-boilerplate.git
  4. npm install
  5. cd lighting-app-boilerplate
  6. node -p “require(‘btcpay’).crypto.generate_keypair().getPrivate().toString(16)”
  7. copy the keypair in a temporary doc
  8. goto btcpayserver/stores/services/ pair the client etc…
  9. copy the merchant key and btcpaypriv into the lines of /routes/invoice.js
  10. add a line into views/index.jade h1 Welcome blabla
  11. npm start
    I see this in the terminal:

[email protected] start /root/lightning-app-boilerplate
node ./bin/www

  1. going to 192.168.178.234:3000 by browser

Nothing happens. And again I have btcpayserver also running here.
And what I want is BTCPayserver in the air with a map separate from btcpayserver to get this new app accessible for the outside world for example http://btcpay.btcexperiments.com/myapp

Any help appreciated.

Perry