πŸš€
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.
Email: [email protected]​

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
1
<div id="root"></div>
2
<script src="https://widget.lnswap.org/widget.js"
3
id="LNSwap-Widget-Script"
4
data-config="{'name': 'lnswap', 'config': {'targetElementId': 'root'}}">
5
</script>
Copied!
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
1
// Populate the required parameters and start the Swap
2
lnswap('swap',
3
'swapType',
4
'user stx address',
5
'amount in STX',
6
'(only for mintnft/triggerswap/trustless rewards/stacking) NFT/Game Contract/Delegate Address',
7
'(only for mintnft) NFT Mint Function Name',
8
'sponsored transaction'
9
'(only for triggertransferswap) receiver stx address',
10
'(only for triggertransferswap) stx transfer memo',
11
'(only for trustless rewards) array of required parameters');
Copied!
​
1
// e.g. Trustlessly Swap Lightning to STX
2
lnswap('swap',
3
'reversesubmarine',
4
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF',
5
5);
Copied!
1
// e.g. (Non-Custodial) Mint NFT with Lightning
2
lnswap('swap',
3
'triggerswap',
4
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF',
5
25,
6
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF.stacks-roots-v2',
7
'claim',
8
'true');
Copied!
1
// e.g. Send STX with Lightning
2
lnswap('swap',
3
'triggertransferswap',
4
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF',
5
25,
6
'',
7
'',
8
'false',
9
'ST1GH2VFAZ7ZB02JHBTMJSQYKJ83ESCNBZ0PJ4MMQ',
10
'test memo description');
Copied!
1
// e.g. Create or Join a Stacks Degens Race
2
lnswap('swap',
3
'sdcreategame', // or sdjoingame
4
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF',
5
25,
6
'ST30VXWG00R13WK8RDXBSTHXNWGNKCAQTRYEMA9FK.trustless-rewards',
7
'',
8
'false',
9
'',
10
'',
11
[description, price, factor, commission, mapy, length, traffic, curves, hours); // [id] for sdjoingame
Copied!
1
// e.g. Stack STX with Lightning
2
lnswap('swap',
3
'stacking',
4
'ST27SD3H5TTZXPBFXHN1ZNMFJ3HNE2070QX7ZN4FF',
5
25,
6
'ST2507VNQZC9VBXM7X7KB4SF4QJDJRSWHG6ERHWB7',
7
'',
8
'false',
9
'',
10
'');
Copied!
Note that you can listen to widget updates from the host page via cross-origin communications as below.
1
// listen to swap events from the widget
2
window.onmessage = function(e) {
3
if (e.data && e.data.target && e.data.target === 'lnswap') {
4
console.log('received data from lnswap widget: ', e.data.data);
5
}
6
};
7
​
8
// data will be in below format:
9
{ target: 'lnswap',
10
data: {
11
txId: 'Stacks txid if exists',
12
swapId: 'ID of the Swap',
13
status: 'Status of the swap'
14
}
15
}
Copied!