Skip to content

About

lnurl server for interacting with a CLN Node

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

Repository files navigation

Core LNURL Server - CLN REST Integration

📌 Overview

This is a Go-based LNURL server that allows users to generate Lightning Network invoices via Core Lightning (CLN) REST API using LNURL-Pay.

This assumes you already have:
✅ A Bitcoin full node running and synced.
✅ A Core Lightning (CLN) node running with at least one active channel.
✅ The CLN REST server enabled and working.
✅ The ability to use either use lightning-cli or your CLN-Rest Server to issue a new rune with restrictions to only use the invoice method

🚀 Features

✅ Dynamic Invoice Generation → Users get a unique invoice every time.
✅ Core Lightning REST API Integration
✅ Configurable Settings → Easily modify ports, CLN node URL, and authentication Runes.
✅ LNURL-Compatible → Works with LNURL-enabled wallets for seamless payments.
✅ Lightning Addresses → [email protected] resolves straight to your own node.
⚡ Nostr Zaps (NIP-57) → optional, off until you configure relays.

📡 API Endpoints

Lightning Address / LNURL-Pay metadata (/.well-known/lnurlp/{username})
This is the endpoint wallets hit first when someone pays [email protected]:

curl "http://localhost:8085/.well-known/lnurlp/user1"

🔹 Example Response:

{
  "tag": "payRequest",
  "callback": "http://localhost:8085/lnurl/pay/user1",
  "metadata": "[[\"text/plain\",\"Pay user1@localhost:8085\"],[\"text/identifier\",\"user1@localhost:8085\"]]",
  "minSendable": 1000,
  "maxSendable": 100000000,
  "commentAllowed": 255
}

Invoice callback (/lnurl/pay/{username})
The wallet follows the callback URL above with the amount in millisatoshis. You can also call it directly:

curl "http://localhost:8085/lnurl/pay/user1?amount=1000000"

The original query-parameter form still works:

curl "http://localhost:8085/lnurl/pay?username=user1&amount=1000000"

🔹 Example Response:

{
  "pr": "lnbc10u1pn6uegtsp...",
  "routes": []
}

Health check (/health) → {"status":"ok"}, handy for reverse proxies and service monitors.

Errors come back in the LNURL format wallets expect, so a failure looks like {"status":"ERROR","reason":"Invalid amount"} rather than a plain-text error.

By default any username works, and this server will fetch an invoice from your node for the amount requested. Set lnurl.allowed_usernames in your config if you would rather serve a fixed list. I'm hoping this makes self custodial lightning addresses on CLN a breeze.

Basically start this server with the proper configs and use any lightning address you want to this server and it will make an invoice that pays your node.

⚡ Nostr zaps (NIP-57)

Add one or more relays to your config and the server advertises allowsNostr, accepts kind-9734 zap requests on the callback, waits for the invoice to settle, then signs and publishes a kind-9735 zap receipt:

zap:
  relays:
    - "wss://relay.damus.io"
    - "wss://nos.lol"

Leave zap.relays empty and zaps stay off — the server behaves exactly as it did before. Advertising allowsNostr with nowhere to publish would make clients wait for a receipt that could never arrive.

Two things to know:

Your rune needs waitinvoice. Receipts are only published once the invoice settles, and the server learns that from CLN's waitinvoice. See the rune section below.

The signing key must be kept. On first run the server generates a keypair and writes it to zap-signing-key next to your config (override with zap.key_file). This is the LNURL provider key from NIP-57, not your nostr identity — do not put your personal nsec here.

Back that file up, and don't regenerate it. Clients validate a zap receipt by checking its author against the nostrPubkey your endpoint serves right now, and kind-9735 receipts are regular events that relays store permanently. If the key changes, every receipt you have ever published stops validating — the zaps don't vanish from relays, they just quietly stop rendering as zaps.

🌐 Putting it behind a domain

Lightning addresses require the .well-known path to be reachable over HTTPS at your domain, so put this server behind a reverse proxy (Caddy, nginx, a Cloudflare tunnel, whatever you already run) and forward these paths to it:

  • /.well-known/lnurlp/*
  • /lnurl/pay/*

The callback URL is built from the incoming Host header, honoring X-Forwarded-Host and X-Forwarded-Proto if your proxy sets them. If your proxy rewrites the Host to something the outside world does not use, pin it with server.domain in your config.

Issue a rune for this server to use

For security, you should issue a new rune for this server to use that is restricted to just the commands it needs: invoice to create invoices, and waitinvoice to notice when one is paid.

⚠️ If you are upgrading and use zaps, reissue your rune. Earlier versions of this readme suggested [["method=invoice"]], which denies waitinvoice. With that rune, payments still arrive but zap receipts are never published, so zaps never show up on the note. If you are not using zaps, the old rune keeps working.

There are a few ways of doing this.

  • lightning-cli
    • Use the cli to issue a new rune with restrictions
    lightning-cli createrune -k "restrictions"='[["method=invoice","method=waitinvoice"]]'
  • You can visit the front end of your REST API (127.0.0.1:3010 is common) and use the gui to log in with your master rune (lightning-cli showrunes to show all your runes). After you are logged in, you can use the gui to make a call to your rest server to create a new rune
    • Under the green POST Dropdown enter
      • rpc_method : createrune
      • payload : {"restrictions": [["method=invoice","method=waitinvoice"]]}
  • Lastly, you can make a curl request from a terminal (this does the same thing as your gui does above)
    curl -X 'POST' \
    'http://127.0.0.1:3010/v1/createrune' \
    -H 'accept: application/json' \
    -H 'Rune: YOUR_MASTER_RUNE_HERE' \
    -H 'Content-Type: application/json' \
    -d '{"restrictions": [["method=invoice","method=waitinvoice"]]}'

In all of these cases you should get a response with the rune and it's summary

{
  "rune": "THIS_IS_YOUR_INVOICE_RUNE",
  "unique_id": "1"
}

Installation

  • Make a directory to put the config and program into
  • Download the latest release binary for your system from the releases page
  • Create a config.yml in the same directory as your executable. There is an example here
  • Run the server ./core-lnurl

Set up a system service on linux

  • Guide and example service file coming soon if you don't already know how to do this

Use nssm to make a Windows service

  • Guide at some point

Docker container by others

🛠️ Building from source

go build -o core-lnurl .
go test ./...

🎯 Summary

🚀 Core LNURL Server lets you create Lightning invoices via CLN REST API.
⚡ Works with LNURL-Pay wallets for easy payments.
🔧 Fully configurable and self-hosted!

📝 License

MIT License – Feel free to modify and contribute! 🚀

Open Source and made with 💦 by OceanSlim

About

lnurl server for interacting with a CLN Node

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages