Skip to content

Instantly share code, notes, and snippets.

@matthewjablack
Last active September 24, 2024 13:07
Show Gist options
  • Save matthewjablack/3062157c9216a3cdbb3f17c294ae38f3 to your computer and use it in GitHub Desktop.
Save matthewjablack/3062157c9216a3cdbb3f17c294ae38f3 to your computer and use it in GitHub Desktop.
# %%
import requests
lightning_address = "matthewjablack@walletofsatoshi.com"
amount_in_sats = 3000
amount = amount_in_sats * 1000
# Split the lightning address into username and domain
username, domain = lightning_address.split('@')
# Construct the URL to fetch the LNURL
url = f"https://{domain}/.well-known/lnurlp/{username}"
print(url)
response = requests.get(url)
lnurl_response = response.json()
print(lnurl_response)
# Extract the callback URL and other details
callback_url = lnurl_response['callback']
min_sendable = lnurl_response['minSendable']
max_sendable = lnurl_response['maxSendable']
# Construct the payment request URL
# amount = min_sendable # or any amount between minSendable and maxSendable
payment_request_url = f"{callback_url}?amount={amount}"
# Make the payment request
payment_response = requests.get(payment_request_url)
payment_request = payment_response.json()
print(payment_request)
# Extract the payment request (invoice)
invoice = payment_request['pr']
print(invoice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment