lnfi-js-sdk
v1.0.0
Published
LnfiSDK is an SDK built on the **Lnfi Protocol**. It provides a unified interface for interacting with wallets that support **Nostr**, managing assets, and performing on-chain actions such as trading, transferring tokens, and placing/canceling orders.
Readme
LnfiSDK
LnfiSDK is an SDK built on the Lnfi Protocol.
It provides a unified interface for interacting with wallets that support Nostr, managing assets, and performing on-chain actions such as trading, transferring tokens, and placing/canceling orders.
Installation
React
npm install lnfi-sdkInclude bolt11.min.js in your public/index.html:
<script src="/yourpath/bolt11.min.js"></script>Node.js
npm install lnfi-sdkHTML
<script src="/yourpath/lnfisdk.umd.js"></script>
<script src="/yourpath/bolt11.min.js"></script>
<script>
const lnfisdk = new LnfiSdk({ env: 'development' });
const supportedProviderNames = Object.keys(lnfisdk.provider.supportedProviderList);
async function onConnect(providerName = 'okx') {
const publicKey = await lnfisdk.provider.connect(providerName);
console.log(publicKey);
}
</script>LnfiSdk
Initialization
import { LnfiSdk } from 'lnfi-sdk';
const lnfisdk = new LnfiSdk({
env: 'development', // Required: 'development' | 'production'
relay: ['wss://relay01.lnfi.network'], // Optional: single relay URL or array of relays
signer: null, // Optional: custom signer instance | window?.okxwallet?.nostr
poolOptions: { getTimeout: 15000 }, // Optional: NostrPool configuration
baseURL: 'https://market-api.lnfi.network', // Optional: API base URL
headers: {}, // Optional: additional HTTP headers
timeout: 10000, // Optional: request timeout in ms
});Available Modules
lnfisdk.market
listOrder(params)takeOrder(params)cancelOrder(orderId)repairOrder(orderId)
lnfisdk.token
approve(spender, amount)transfer(to, amount)addAddressBook(label, address)deposit(params)withdraw(params)
lnfisdk.assets
getBalance(address)getTokenList()getAllowance(owner, spender)getFundingRecords(address)getTokenEvents(token)getHolders(token)getHolder(token, address)getHolderSummary(token)getPayeeList(address)
lnfisdk.marketApi
getMarketTokenList()getMarketOrderListing(params)getOrderHistory(address)getMarketMyOrder(address)getKline(symbol, interval)
lnfisdk.lock
getLockList(address)
Usage Examples
Market Example
const market = lnfisdk.market;
await market.listOrder({
side: 'sell',
amount: '100',
price: '101',
buyOrSellTokenName: 'TRICK',
payTokenName: 'SATS'
});Token Example
const token = lnfisdk.token;
await token.approve('recipient_address', 100);Running Commands
await lnfisdk.runCommand('NOSTR_MESSAGE', 'SEND_TO_ADDRESS', false);LnfiNostr
LnfiNostr is a helper class for managing Nostr identities and signing messages/events.
It supports three initialization methods, and you can choose one of them:
- A Nostr private key
- A connected EVM wallet
- A connected BTC wallet
Initialization
import LnfiNostr from 'lnfi-sdk';
// Using a Nostr private key
const lnfiNostr1 = new LnfiNostr({ privateKey: 'nsec1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' });
// Using an EVM wallet
// evm can be a boolean (true for window.ethereum) or a custom provider object
const lnfiNostr2 = new LnfiNostr({ evm: true });
// Using a BTC wallet
// btc can be a boolean (true for window.unisat) or a custom provider object
const lnfiNostr3 = new LnfiNostr({ btc: true });Note: At least one of
privateKey,evm, orbtcmust be provided.
If none is provided, the constructor will throw an error.
Methods
signMessage(message)→ Signs a message using the connected wallet or private key.nip04.encrypt(pubkey, message)→ Encrypts a message using NIP-04.getPublicKey()→ Returns the public key associated with the wallet or private key.getPrivateKey()→ Returns the decrypted Nostr private key.signEvent(event)→ Signs a Nostr event and returns the event object withsig.
Parameters
- privateKey: Nostr private key (
nsec1...or 64-char hex). - evm: Either
true(useswindow.ethereum) or a custom EVM provider object. - btc: Either
true(useswindow.unisat) or a custom BTC provider object.
Examples & Tests
See src/main.jsx for examples.
Running the Test Suite
- Install dependencies:
npm install- Start development server (optional for local tests/examples):
npm run dev- Run tests (if using Jest):
npx jestLicense
MIT License © 2025 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.
