Created
January 28, 2025 07:08
-
-
Save rossigee/c9f1cf7ff80dbb2bbf386d488f9d9f90 to your computer and use it in GitHub Desktop.
Basic python script to request an LN invoice for a given Lightning Address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import requests | |
import json | |
# Take first argument as address to send satoshis to | |
email = sys.argv[1].split("@") | |
username = email[0] | |
domain = email[1] | |
# Take second argument as amount in satoshis to send | |
amount = int(sys.argv[2]) * 1000 # Convert to millisatoshis | |
# Construct LNURL | |
lnurl = f"https://{domain}/.well-known/lnurlp/{username}" | |
print(f"LNURL: {lnurl}") | |
# Look up LSP details using LNURL | |
response = requests.get(lnurl) | |
data = response.json() | |
callbackurl = data["callback"] | |
# Request invoice for amount from LSP callback | |
invoiceurl = f"{callbackurl}?amount={amount}" | |
print(f"Invoice URL: {invoiceurl}") | |
response = requests.get(invoiceurl) | |
data = response.json() | |
pr = data['pr'] | |
print() | |
print(f"Pay to address: {pr}") | |
print() | |
# Submit payment for invoice | |
#... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment