Guide

How to Send Payments

Send Payments over the Lightning Network.

Encoded Payment Example
lnbc3424740n1p3u42h3pp5jq0gcxdsa2zufhudrzr7rfl8g7tymzk4rnhnvmah7c6lam3yfpgqdp62djkce3dwpshjmt9de6zqen0wgsxx6rpdehx2mpqwfjkyctvv9hxx6twvucqzpgxqyz5vqsp5zflxnkr3e9qt8uaxgc4nun3ee64gz9p986q6ghpmtgegaqwqpm7s9qyyssql0wc7mtpk9rq6engcf32xehg9a53w53m0j0c0vhcwgdk8ekx5axqpf30e7zp8fr6

In this guide, you will learn how to integrate and use our server-side SDKs to pay a Lightning Invoice seamlessly.

Step 1

Open a Lightspark Account

Opening an account with Lightspark is fast and easy. Enter your name, your email, your company’s name and create a password and you’ll be able to instantly use our test mode and experiment with Lightning.

When you are ready to go live and switch to production mode, hit the toggle at the top of your dashboard. You’ll have to provide some additional information about your business and will be on your way to sending and receiving Lightning payments!

Step 2

Generate a Lightspark Token

Once your account has been set up, head to the API Configuration page and generate a Lightspark Token.

Step 3

Install the Lightspark SDK

Install the Lightspark package and import it in your code. Alternatively, you can download the project files directly from our Github repository.

Javascript

Python

Rust

Kotlin

Install the Lightspark package
Python
$ pip3 install lightspark

Step 4

Get an invoice

If you are in test mode, you can ask Lightspark to generate an invoice by clicking here. You will be able to set the amount and memo for the invoice.

If you are already in production mode, use any Lightning wallet to generate a BOLT11-compliant invoice.

Step 5

Send a payment

Using our SDK library and your Lightspark Token, instantiate a Lightspark Client and pay your invoice in a few lines of code.

Install the Lightspark package
Python
import lightspark client = lightspark.LightsparkSyncClient(     api_token_client_id=os.environ.get("LIGHTSPARK_API_TOKEN_CLIENT_ID"),     api_token_client_secret=os.environ.get("LIGHTSPARK_API_TOKEN_CLIENT_SECRET"), ) # Use the invoice string you obtained during Step 4 encoded_invoice = "lnbc3424740n1p3u42h3pp5jq[...]7dpy6v6m807egpjzydw2" payment = client.pay_invoice(     encoded_invoice=encoded_invoice,     timeout_secs=60,     maximum_fees_sats=500, ) print(f"Congrats! You sent your first Lightning payment! Its ID is {payment.id} and its current status is {payment.status}.")

Step 6 (optional)

Check the payment status

Lightning payments are asynchronous so they may sometimes return a PENDING status. You can easily query the payment again later to check on its status using the code below:

Install the Lightspark package
Python
updated_payment = client.get_entity(payment.id, lightspark.OutgoingPayment) print(f"New status = {updated_payment.status}")

Alternatively, you can subscribe to our webhooks to get real time updates on your payments. See our webhooks documentation.