🚀

Widget Quick Start

All swaps are trustless and there's no risk to user funds. If user navigates away from the page or swap fails for any reason, user's Lightning invoice payment will be canceled in ~24 hours and their funds will return to their Lightning wallet.

No need for API keys

You can integrate the library into your app and start making requests on mainnet right away. If you need help integrating or testing the widget, feel free to contact us.
If you prefer testnet you can test the available widget functions at http://testnet.lnswap.org:8081 or embed the widget into your site from http://testnet.lnswap.org:8081/widget.js.

Install the widget

The best way to interact with our API is to use the below code to make it available on your site:
JS
<div id="root"></div>
<script src="https://widget.lnswap.org/widget.js"
id="LNSwap-Widget-Script"
data-config="{'name': 'lnswap', 'config': {'targetElementId': 'root'}}">
</script>
Note: You can use the same script on any site. Just drop into your static page and lnswap function should be available globally or under window.lnswap

Create your first swap request

To create your first swap request, populate the values below and call the lnswap function which will make the required call to LNSwap API.
How it works: Stacks contract calls are triggered when required STX (or SIP10) is locked into the swap contract and once it's confirmed, user calls one of the trigger calls that can be found in the triggerswap contract.
Take a look at different swap types you can trigger using the widget:
Generic
LN->STX
Mint with LN
Send STX with LN
Trustless Rewards
Stacking
// Populate the required parameters and start the Swap
lnswap('swap',
'swapType',
'user stx address',
'amount in STX',
'(only for mintnft/triggerswap/trustless rewards/stacking) NFT/Game Contract/Delegate Address',
'(only for mintnft) NFT Mint Function Name',
'sponsored transaction'
'(only for triggertransferswap) receiver stx address',
'(only for triggertransferswap) stx transfer memo',
'(only for trustless rewards) array of required parameters');
// e.g. Trustlessly Swap Lightning to STX
lnswap('swap',
'reversesubmarine',
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF',
5);
// e.g. (Non-Custodial) Mint NFT with Lightning
lnswap('swap',
'triggerswap',
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF',
25,
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF.stacks-roots-v2',
'claim',
'true');
// e.g. Send STX with Lightning
lnswap('swap',
'triggertransferswap',
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF',
25,
'',
'',
'false',
'ST1GH2VFAZ7ZB02JHBTMJSQYKJ83ESCNBZ0PJ4MMQ',
'test memo description');
// e.g. Create or Join a Stacks Degens Race
lnswap('swap',
'sdcreategame', // or sdjoingame
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF',
25,
'ST30VXWG00R13WK8RDXBSTHXNWGNKCAQTRYEMA9FK.trustless-rewards',
'',
'false',
'',
'',
[description, price, factor, commission, mapy, length, traffic, curves, hours); // [id] for sdjoingame
// e.g. Stack STX with Lightning
lnswap('swap',
'stacking',
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF',
25,
'ST2507VNQZC9VBXM7X7KB4SF4QJDJRSWHG6ERHWB7',
'',
'false',
'',
'');
Note that you can listen to widget updates from the host page via cross-origin communications as below.
// listen to swap events from the widget
window.onmessage = function(e) {
if (e.data && e.data.target && e.data.target === 'lnswap') {
console.log('received data from lnswap widget: ', e.data.data);
}
};
// data will be in below format:
{ target: 'lnswap',
data: {
txId: 'Stacks txid if exists',
swapId: 'ID of the Swap',
status: 'Status of the swap'
}
}