lnlink-js-sdk
v1.0.0
Published
It is an SDK library developed based on the Lnfi protocol, used to connect plugin wallets that support NOSTR, perform transactions, and place orders.
Readme
LnfiSDK
It is an SDK library developed based on the Lnfi protocol, used to connect plugin wallets that support NOSTR, perform transactions, and place orders.
Support method list
lnfisdk.market
- listOrder
- takeOrder
- cancelOrder
- repairOrder
lnfisdk.token
- approve
- transfer
- addAddressBook
- deposit
- widthdraw
lnfisdk.assets
- getBalance
- getTokenList
- getAllowance
- getFundingRecords
- getTokenEvents
- getHolders
- getHolder
- getHolderSummary
- getPayeeList
lnfisdk.marketApi
- getMarketTokenList
- getMarketOrderListing
- getOrderHistory
- getMarketMyOrder
- getKline
lnfisdk.lock
- getLockList
Setup
React
install
yarn add lnfi-sdk
//import bolt11min.js to public/index.html through script src
<script src=`${yourpath}/bolt11.min.js``></script>code
import {useCallback} from 'react
import LnLinkSdk from 'lnfi-sdk'
const lnfisdk = new LnLinkSdk({ env: 'development'}) // env: development | production
const onTransfer = useCallback(async()=>{
const res = await lnfisdk.token.transfer({ tokenName: 'NOSTR', amount: 1, to: 'npub1zptcf2v9ms5dgd8mgulsckk04l9upr3lnerk6ckh9zyntzu0ness753zx8' })
},[])
return <>
{your code}
</>
Node.js
install
yarn add websocket-polyfill bolt11 lnfi-sdkcode
import 'websocket-polyfill'
import 'bolt11'
import LnLinkSdk from 'lnfi-sdk'
const privateKey='45d914aef9c2f85a47b242ef684245c02e0af93d6f9031fcc3444ede8ac0a295'
const lnfisdk = new LnLinkSdk({ env: 'development', privateKey, poolOptions:{getTimeout:10*1000} })
const res = await lnfisdk.market.listOrder({ side:'sell',amount:'100',price:'101',buyOrSellTokenName:'TRICK',payTokenName:'SATS'})
// You can see more examples in the tests directory
HTML
<scrpt src=`${youpath}/lnfisdk.umd.js`>
<script src=`${yourpath}/bolt11.min.js``></script>
<script>
const lnfisdk = new LnLinkSdk({ env: 'development' })
const supportedProviderNames = Object.keys(lnfisdk.provider.supportedProviderList)
async function onConnect(providerName='alby') {
const res = await lnfisdk.provider.connect(providerName)
}
</script>Example
src/tests
Running the test suite
yarn node --experimental-vm-modules $(yarn bin jest) --detectOpenHandlesLicense
MIT License
Copyright (c) 2024 Luke
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
