npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@synonymdev/blocktank-lsp-http-client

v2.3.0

Published

Blocktank Http Api Client

Downloads

514

Readme

blocktank-lsp-http-client

NPM version

Client to interact with the blocktank-lsp-http service.

Usage

Pay and open channel

import { BlocktankClient } from '@synonymdev/blocktank-lsp-http-client';

const client = new BlocktankClient();
const lspBalanceSat = 100*1000
const leaseDurationWeeks = 10
const order = await client.createOrder(lspBalanceSat, leaseDurationWeeks)
console.log(`Order expires at ${order.expiresAt}. Pay and open before this date.`)

// Pay either ln invoice or onchain. Ln invoice is automatically refunded if the channel is not opened before the order expires.
console.log(`Either pay ${order.feeSat}sat to bolt11 invoice ${order.payment.bolt11Invoice.request} or to onchain to ${order.payment.onchain.address}.`)

const expected0ConfFee = await client.getMin0ConfTxFee(order.id)
console.log(`Onchain payments that should be accepted as 0conf need to have a minimal fee of ${expected0ConfFee.satVByte}sat/vbyte.`)

// Check order status
const updatedOrder = await client.getOrder(order.id)
console.log(`Payment status: ${updatedOrder.payment.state}.`)
console.log(`Establish a peer connection to ${updatedOrder.lspNode.connectionStrings} in case you do not have a public address.`)

// Open channel
const announceChannel = true
// If only a pubkey is provided here, the client MUST establish a peer connection to the LSP node before opening the channel.
const connectionStringOrPubkey = '03775370500b8c8642617bced873e7914eaec4f6a79c9ca99043224a1b28677082@172.19.0.7:9735'
const openOrder = await client.openChannel(connectionStringOrPubkey, announceChannel)
console.log(`Funding tx outpoint: ${order.channel.fundingTx.id}:${order.channel.fundingTx.vout}.`)

Advanced Order Options

These options can be used to customize the order.

import { BlocktankClient } from '@synonymdev/blocktank-lsp-http-client';

const client = new BlocktankClient();
const lspBalanceSat = 100*1000
const leaseDurationWeeks = 10
const order = await client.createOrder(lspBalanceSat, leaseDurationWeeks, {
    clientBalanceSat: 20*2000, // How much initial spending balance client like to have. Max the same as lspBalanceSat.
    couponCode: 'SATOSHI_20PERCENT',
    lspNodeId: '0296b2db342fcf87ea94d981757fdf4d3e545bd5cef4919f58b5d38dfdd73bf5c9', // Choose the LSP node to open the channel with. MUST be from the list in `client.getInfo()`. If not set, the LSP will choose the best node for you.
})

General Info and Order Boundaries

LSP node list + order boundaries. These values are used to validate the order.

import { BlocktankClient } from '@synonymdev/blocktank-lsp-http-client';

const client = new BlocktankClient();
const info = await client.getInfo()

console.log(`Blocktank info`, info)
{
    version: 2,
    nodes: [ // Blocktank LSP nodes
      {
         alias: "Blocktank",
         pubkey: "0296b2db342fcf87ea94d981757fdf4d3e545bd5cef4919f58b5d38dfdd73bf5c9",
         connectionStrings: [
           "0296b2db342fcf87ea94d981757fdf4d3e545bd5cef4919f58b5d38dfdd73bf5c9@146.148.127.140:9735"
         ]
       }    
    ],
    options: {
        minChannelSizeSat: 1000, // Min channel size in satoshi. lspBalanceSat + clientBalanceSat MUST be >= minChannelSizeSat.
        maxChannelSizeSat: 3170000, // Max channel size in satoshi. lspBalanceSat + clientBalanceSat MUST be <= minChannelSizeSat.
        minExpiryWeeks: 1, // How long the channel MUST be leased for min.
        maxExpiryWeeks: 53, // How long the channel may be leased for max.
        minPaymentConfirmations: 0, // Minimum onchain payment confirmations required for the order.
        minHighRiskPaymentConfirmations: 1, // Minimum onchain payment confirmations required for orders with clientBalance.
        max0ConfClientBalanceSat: 317000, // Max clientBalanceSat for orders with 0 payment confirmations.
}

Channel Open error handling

import { BtChannelOrderErrorType } from '@synonymdev/blocktank-lsp-http-client';

try {
    await client.openChannel(connectionStringOrPubkey, announceChannel)
} catch (e) {
    if (e.data?.name === 'ChannelOpenError') {
        const errorType: BtChannelOrderErrorType = e.data.type

        if (errorType === BtChannelOrderErrorType.PEER_NOT_REACHABLE) {
            // LSP could not establish a peer connection to the client.
        } else if (errorType === BtChannelOrderErrorType.WRONG_ORDER_STATE) {
            // Order is not in the right state to open the channel. Order must be paid and not expired.
        } else if (errorType === BtChannelOrderErrorType.CHANNEL_REJECTED_BY_DESTINATION) {
            // Client rejected the channel opening.
        } else if (errorType === BtChannelOrderErrorType.CHANNEL_REJECTED_BY_LSP) {
            // LSP rejected the channel or node.
        } else if (errorType === BtChannelOrderErrorType.BLOCKTANK_NOT_READY) {
            // Blocktank is not ready.
        }
    }
    // Other error
    throw e
}

Versioning

  1. Increase version in package.json.
  2. Add changes to CHANGELOG.md.
  3. Commit changes.
  4. Tag new version: git tag v0.1.0.
  5. Push tag git push origin v0.1.0.
  6. Publish to npm: npm publish.