LNPay JavaScript SDK - at the moment a basic wrapper for the LNPay API
You can get it on npm.
npm install lnpay-js --save
Or if you're not into package management, just download a ZIP file.
First, include the script located on the dist
folder or load it from unpkg.
<script src="https://unpkg.com/lnpay-js@^0.1/dist/lnpay.min.js"></script>
Now, you need to instantiate it with a Public API Key from LNPay.co
let publicApiKey = '';
LNPay.Initialize(publicApiKey);
Usage - Documentation
The first alpha version of this SDK is mainly a wrapper for the LNPay API
Everyhing revolves around the wallet and Wallet Access Keys (WAK) which grant various levels of permission.
let myWallet = new LNPayWallet(walletAccessKey);
myWallet.getInfo(function(result) {
console.log('Balance:' + result.balance);
}
);
You can create a wallet from the UI or via the API. When you create a wallet via the API, Wallet Access Keys (WAK) are returned. You need to save these.
let walletParams = {"user_label":"My wallet"};
LNPay.createWallet(walletParams,
function(result) {
console.log(result);
}
);
let myWallet = new LNPayWallet(walletAccessKey);
let invoiceParams = {"num_satoshis":2,"memo":"Tester"};
myWallet.createInvoice(invoiceParams,
function(result) {
console.log(result);
}
);
let myWallet = new LNPayWallet(walletAccessKey);
let invoiceParams = {"payment_request":"lnbc1111..."};
myWallet.payInvoice(invoiceParams,
function(result) {
console.log(result);
}
);
let myWallet = new LNPayWallet(walletAccessKey);
let transferParams = {"dest_wallet_id":"wa_xxxxx","num_satoshis":22,"memo":"Transfer Memo"};
myWallet.internalTransfer(transferParams,
function(result) {
console.log(result);
}
);
let myWallet = new LNPayWallet(walletAccessKey);
let queryParams = {};
myWallet.getTransactions(queryParams,
function(result) {
console.log(result);
}
);
let lnurlParams = {"num_satoshis":12,"memo":"SatsBack!"};
let myWallet = new LNPayWallet(walletAccessKey);
myWallet.getLnurl(lnurlParams,
function(result) {
console.log(result);
}
);
let lntx_id = "lntx_Mxxxxx";
let lntx = new LNPayLnTx(lntx_id);
lntx.getInfo(function(result) {
console.log("Is Settled" + result.settled);
}
);
You will need to have nodejs installed.
Clone the repository
- open the command line and switch into the project folder
npm install
npm install -g gulp
gulp
to see the list of available tasks
gulp build
dumps a plain and a minified file from all files in the foldersrc
into the folderdist
.gulp clean
removes all files in the folderdist
.gulp test
runs the tests and linting for all files in the foldersrc
.
The structure for this SDK cloned from here.
This software is published under the MIT-License. See 'license' for more information.