Initiate Bitcoin Lightning withdrawals on OpenNode API

Initiate Bitcoin Lightning withdrawals on OpenNode API

Hey, welcome, this is my second article on How to Integrate OpenNode. In this article, you will learn how to initiate bitcoin lightning withdrawal on OpeNode.

OpenNode is a bitcoin payment processor. It provides multiple API endpoints for businesses to accept and receive bitcoin payments using any programming language.

requirements

I assume you have gone through the first part. If yes? you should have the following:

Let's begin.

initiate withdrawal

On the Postman collection, open the transfers folders and you will see multiple requests.

image.png

Click on initiate withdrawal and in the request body, you should see JSON data.

image.png

The type key allows you to specify the type of withdrawal (chain, ln, or wire). On the Postman, you can see I entered "ln" instead of "chain" since I want to withdraw bitcoin via Lightning Network.

You can also see amount. It is to be entered in satoshi, as you can see, I am withdrawing 10,000 satoshis to an address.

The address depends on the type. Since it is "ln" the address has to be a Lightening Payment address.

The callback_url is to recieve the withdrawal webhook. This can be a URL within your application or a third-party webhook service.

Now, try to run the request and you will get a response.

image.png

lnurl withdrawal

You can initiate LNURL withdrawal on OpenNode. LNURL (Lightning Network URL) removes the unpleasant process of having to copy and paste LN addresses, then generate an invoice and submit it. With LNURL, users can just scan the QR code or click a link, and everything will be done automatically.

On the Postman collection, you will see the Initiate LNURL withdrawal request. This request has multiple JSON keys on the Body. Although, only the min_amount and max_amount are required.

image.png

The min_amount and max_amount is the minimum and maximum amount in satoshi.

The description is the message to be displayed on the receiver or client's wallet. You can also specify the expiry_date and a callback_url. The expiry_date is by default 365 days.

running the request

When you run the request and get a successful response. From the response, you can then generate a QR code with the uri. The user can scan this code with their Lightning-enabled wallet.

getting withdrawal info

You may want to get details of a single withdrawal. This is useful to revalidate the status of a transaction in case a webhook fails, it does.

Click on the withdrawal info request on the Postman. Replace the withdrawal-id on the URL with the id of the withdrawal you want to retrieve. You get an id anytime you initiate a withdrawal.

image.png

Run the request and you will get the withdrawal information. The result has status and it can either be confirmed or failed.

conclusion

Now you know exactly how to initiate Lightning withdrawal through OpenNode. If you like this article or need clarity, kindly reply in the comment below.

Here are some useful links for this article: