lntip/README.md

255 lines
9.5 KiB
Markdown
Raw Normal View History

<p align="center"><br/><br/><img src="https://raw.githubusercontent.com/bumi/lnme/master/icon/lnme-icon-rrect.svg" height="128" width="128" /><br/><br/></p>
<h1 align="center">LnMe - your friendly payment page</h1><br/><br/>
2019-01-08 15:55:22 +00:00
2021-08-28 20:46:50 +00:00
LnMe is a personal Bitcoin Lightning payment page/widget and self-hosted [Lightning Address](https://lightningaddress.com/) server.
2019-01-08 15:55:22 +00:00
2020-10-24 00:06:52 +00:00
![demo](./lnme-demo.gif)
2021-08-28 20:46:50 +00:00
**See it in action: [ln.michaelbumann.com](https://ln.michaelbumann.com/) - my lightning address: bumi@ln.michaelbumann.com**
2019-01-08 15:55:22 +00:00
2021-08-28 20:46:50 +00:00
LnMe focusses on simplicity and ease of deployment. It connects to an existing lightning node (currently LND is supported).
2019-01-08 16:02:20 +00:00
2021-08-27 22:42:04 +00:00
LnMe is one [simple executable](https://github.com/bumi/lnme/releases) file that can be deployed anywhere with no dependencies. (on your own node or for example with [one click on Heroku](#heroku))
2019-02-20 21:44:44 +00:00
2021-08-30 07:59:17 +00:00
## Features
- [x] Embeded payment page - customizable (see demo)
- [x] [Lightning Address](https://lightningaddress.com/) support
- [x] WebLN integration - if [WebLN](https://webln.dev/) is not available a QRcode and the invoice will be shown
- [x] [JavaScript widget](#javascript-widget-integration) for existing websites
- [x] [Invoice API](https://github.com/bumi/lnme/wiki/API) - simple REST API to create LN invoices from existing JS code
- [ ] [LNURL-pay](https://github.com/fiatjaf/lnurl-rfc/blob/luds/06.md) support
2019-01-08 15:55:22 +00:00
## Installation
2021-08-27 13:55:51 +00:00
LnMe connects to your [LND node](https://github.com/lightningnetwork/lnd/blob/master/docs/INSTALL.md), so a running LND node is required.
2021-08-27 22:42:04 +00:00
LnMe can easily run next to LND on the same system or any other hosting provider.
2019-01-08 15:55:22 +00:00
There are no other dependencies. Simply download the binary and run it!
2021-08-30 07:59:17 +00:00
2020-10-24 09:42:06 +00:00
1. Download the latest [release](https://github.com/bumi/lnme/releases)
2020-10-25 10:00:54 +00:00
2. Run `lnme`
2020-10-23 18:38:18 +00:00
3. Done.
2019-01-08 15:55:22 +00:00
2020-10-25 10:23:33 +00:00
### Build from source
2020-10-25 10:24:10 +00:00
1. `$ git clone https://github.com/bumi/lnme.git && cd lnme`
2. `$ go install`
3. `$ rice embed-go && go build`
4. `$ ./lnme`
2020-10-25 10:23:33 +00:00
2021-08-27 08:17:30 +00:00
Note: You must have [go.rice installed](https://github.com/GeertJohan/go.rice#installation)
2021-11-06 17:39:17 +00:00
### Running in Docker
LnMe is now available in docker too.
You can start LnMe like this: `docker run -it --rm ghcr.io/bumi/lnme:master`
A list of existing tags is available [here](https://github.com/bumi/lnme/pkgs/container/lnme).
2019-01-08 15:55:22 +00:00
### Configuration
2020-10-23 18:38:18 +00:00
#### LND configuration
To connect to the lnd node the cert, macaroon and address of the lnd node has to be configured. LnMe uses the LND defaults.
2019-01-08 15:55:22 +00:00
* `lnd-address`: Host and port of the LND gRPC service. default: localhost:10009
* `lnd-cert-path`: Path to the LND TLS cert file. default: ~/.lnd/tls.cert
* `lnd-macaroon-path`: Path to the LND macaroon file. default: ~/.lnd/data/chain/bitcoin/mainnet/invoice.macaroon (invoice.macaroon is recommended)
Instead of the path to the macaroon and cert files you can also provide the hex strings:
* `lnd-cert`: LND TLS cert as HEX string.
2020-10-25 23:59:09 +00:00
* `lnd-macaroon`: LND macaroon HEX string. (invoice.macaroon is recommended)
2020-10-23 18:38:18 +00:00
#### Other configuration
2020-10-23 18:43:57 +00:00
* `static-path`: Path to a folder that you want to serve with LnMe (e.g. /home/bitcoin/lnme/website). Use this if you want to customize your ⚡website. default: disabled
* `disable-website`: Disable the default LnMe website. Disable the website if you only want to embed the LnMe widget on your existing website.
* `disable-cors`: Disable CORS headers. (default: false)
* `disable-ln-address`: Disable [Lightning Address](https://lightningaddress.com/) handling.
* `port`: Port to listen on. (default: 1323)
2020-10-23 18:43:57 +00:00
* `request-limit`: Limit the allowed requests per second. (default: 5)
2020-10-23 18:38:18 +00:00
Depending on your deployment needs LnMe can be configured using the following options:
1. Command line flags
2. Environment variables
3. Config TOML file
2020-10-23 18:38:18 +00:00
#### Examples:
2019-01-08 15:55:22 +00:00
##### Command line flags:
2020-10-24 13:26:47 +00:00
$ lnme --help
$ lnme --lnd-address=lndhost.com:10009 --port=4711
2020-10-24 13:26:47 +00:00
$ lnme --disable-website
2019-01-08 15:55:22 +00:00
##### TOML config file
See [config.toml.example](./toml.config.example) for an example file.
$ lnme --config=/path/to/config.toml
##### Environment variables
All environment variables must be prefixed by `LNME_` use `_` instead of `-`
$ LNME_LND_ADDRESS=127.0.0.1:10005 lnme
2021-08-27 09:52:17 +00:00
### LND Permissions
LnMe needs the following LND permissions:
2021-10-29 15:29:57 +00:00
* Read/Write permission for `invoices`
* Write permission for `address` (if you want to use the onchain option)
2021-08-27 09:52:17 +00:00
Use the LND [macaroon bakery](http://macaroon-bakery.freedomnode.com/) to create a new macaroon for LnMe.
2021-08-29 07:00:23 +00:00
To get the HEX versions of the files use `xxd -plain` e.g. `xxd -plain invoice.macaroon | tr -d '\n'`
2020-10-23 18:38:18 +00:00
2021-08-27 13:55:51 +00:00
### TOR
LnMe can connect to your lightning node through [Tor](https://www.torproject.org/). You need to have Tor installed on your system and then simply provide your LND `.onion` address (don't forget to specify the port).
2021-08-30 08:04:59 +00:00
## Deployment
2020-10-25 10:00:54 +00:00
2021-08-30 08:04:59 +00:00
It is the easiest to run LnMe on the same node as LND. But you can run it anywhere as long as your LND node is accessible. Simply run the binary and make sure the PORT is accessible.
2020-10-26 16:44:44 +00:00
2021-10-29 09:51:35 +00:00
If you run LNMe on a different server you will need your LND address, the LND TLS certificate (HEX) and the macaroon (HEX). (see above)
2020-10-26 16:44:44 +00:00
2021-10-29 09:51:35 +00:00
When getting the HEX of the LND files use `xxd -plain YOUR_FILE.cert | tr -d '\n'`. For example for the TLS certificate, use `xxd -plain tls.cert | tr -d '\n'`.
2021-08-27 09:52:17 +00:00
2021-10-29 09:51:35 +00:00
The TLS cert is located in the lnd directory:
* ~/umbrel/lnd/tls.cert on Umbrel
* /mnt/hdd/lnd/tls.cert on Raspiblitz
* Can also be located in ~/.lnd
2021-10-29 09:51:35 +00:00
You should find the macaroon files in the LND data dir (e.g. ~.lnd/data/chain/bitcoin/mainnet/) or see "LND Permissions" how to create a new one.
### Heroku
One click deployment with Heroku:
2020-10-26 16:44:44 +00:00
[![Deploy on Heroku](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/bumi/lnme)
2021-08-27 22:05:07 +00:00
Here is a [Video Demo of the Heroku deployment](https://www.youtube.com/watch?v=hSFXhnLp_Rc)
In order to run Tor on Heroku, the Heroku deployment includes a non-official buildpack: https://github.com/iamashks/heroku-buildpack-tor-proxy
This buildpack can be disabled and removed if not needed or desired, through the Settings tab on the Heroku dashboard, or by editing app.json and removing the buildpack.
Lastly, using the Heroku deployment, you can link the app to your own domain by following the directions here: https://help.heroku.com/MTG1BIA7/how-do-i-connect-a-domain-to-my-heroku-app
2021-08-30 08:04:59 +00:00
### Deployment Notes
2020-10-26 16:44:44 +00:00
2020-10-25 10:00:54 +00:00
To run LnMe as systemd service have a look at the [systemd service example config](https://github.com/bumi/lnme/blob/master/examples/lnme.service)
I am running LnMe behind a reverse proxy using [caddy](https://caddyserver.com/) which comes with [fully-managed HTTPS](https://caddyserver.com/docs/quick-starts/https) via [letsencrypt](https://letsencrypt.org/).
Example Caddyfile:
```
lnme.michaelbumann.com {
reverse_proxy 127.0.0.1:1323
}
```
`$ caddy --config /etc/caddy/Caddyfile`
2021-08-30 08:04:59 +00:00
## Feature Usage
### Lightning Address
The Lightning Address is an Internet Identifier that allows anyone to send you Bitcoin over the Lightning Network.
Lightning Address builds on [LNURL-pay](https://github.com/fiatjaf/lnurl-rfc/blob/luds/06.md) LnMe handles the necessary requests for you.
For more information check out the website: [lightningaddress.com](https://lightningaddress.com/)
Your Lightning Address: `{anything}@{your domain}`
2020-10-23 18:38:18 +00:00
### Customize your ⚡ website
2020-10-23 18:43:57 +00:00
LnMe comes with a default website but you can easily configure and build your own using the the LnMe JavaScript widget or JSON API.
2020-10-23 18:38:18 +00:00
2020-10-24 09:42:06 +00:00
Take a look at the [embedded default website](https://github.com/bumi/lnme/blob/master/files/root/index.html) for an example and use the `--static-path` option to configure LnMe to serve your static file.
2020-10-23 18:38:18 +00:00
1. Create a new folder (e.g. /home/satoshi/my-ln-page)
2. Create your index.html
3. Run lnme: `lnme --static-path=/home/satoshi/my-ln-page
2019-02-20 21:44:44 +00:00
2019-01-08 15:55:22 +00:00
### JavaScript Widget integration
2020-10-23 18:38:18 +00:00
You can integrate the LnMe widget in your existing website.
#### 1. Add the LnMe JavaScript files
2019-01-08 15:55:22 +00:00
```html
2020-10-23 18:38:18 +00:00
<script data-lnme-base-url="https://your-lnme-host.com:1323" src="https://your-lnme-host.com/lnme/lnme.js"></script>
2019-01-08 15:55:22 +00:00
```
2020-10-23 18:38:18 +00:00
#### 2. Usage
2019-01-08 15:55:22 +00:00
2020-10-23 18:38:18 +00:00
To request a lightning payment simply call `request()` on a `new LnMe({value: value, memo: memo})`:
2019-01-08 16:02:20 +00:00
2019-01-08 15:55:22 +00:00
```js
2020-10-23 18:38:18 +00:00
var lnme = new LnMe({ value: 1000, memo: 'high5' });
lnme.request();
2019-01-08 15:55:22 +00:00
```
2019-01-08 16:02:20 +00:00
Use it from a plain HTML link:
2020-10-23 18:38:18 +00:00
2019-01-08 16:02:20 +00:00
```html
2020-10-23 18:38:18 +00:00
<a href="#" onclick="javascript:new LnMe({ value: 1000, memo: 'high5' }).request();return false;">Tip me</a>
2019-01-08 16:02:20 +00:00
```
##### More advanced JS API:
2019-01-08 15:55:22 +00:00
```js
2020-10-23 18:38:18 +00:00
let lnme = new LnMe({ value: 1000, memo: 'high5' });
2019-01-08 15:55:22 +00:00
// get a new invoice and watch for a payment
// promise resolves if the invoice is settled
2020-10-23 18:38:18 +00:00
lnme.requestPayment().then(invoice => {
2019-01-08 15:55:22 +00:00
alert('YAY, thanks!');
});
// create a new invoice
2020-10-23 18:38:18 +00:00
lnme.addInvoice().then(invoice => {
2019-01-09 11:08:50 +00:00
console.log(invoice.PaymentRequest)
2019-01-08 15:55:22 +00:00
});
// periodically watch if an invoice is settled
2020-10-23 18:38:18 +00:00
lnme.watchPayment().then(invoice => {
2019-01-08 15:55:22 +00:00
alert('YAY, thanks!');
});
```
2021-08-27 22:42:04 +00:00
## Motivation
I wanted a simple way for people to send Lightning payments using my own lightning node.
BTCPay Server is too big and hard to run for that and I do not need most of its features.
## Development
2020-10-23 18:38:18 +00:00
Use `go run` to ron the service locally:
2019-02-20 21:44:44 +00:00
2020-10-23 18:38:18 +00:00
$ go run lnme.go --address=127.0.0.1:10009 --cert=/home/bitcoin/lightning/tls.cert --macaroon=/home/bitcoin/lightning/invoice.macaroon
2020-10-24 13:33:58 +00:00
## Build
2021-08-27 08:17:30 +00:00
LnMe uses [go.rice](https://github.com/GeertJohan/go.rice) to embed assets (HTML, JS, and CSS files). run `rice embed-go` (needs to be [installed](https://github.com/GeertJohan/go.rice#installation))
2020-10-24 13:33:58 +00:00
$ rice embed-go
$ go build
2019-01-08 15:55:22 +00:00
## Contributing
2020-10-23 18:38:18 +00:00
Bug reports and pull requests are welcome on GitHub at https://github.com/bumi/lnme
2019-01-08 15:55:22 +00:00
## License
Available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).