blocktank-lsp-http-client
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.`)
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.`)
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.`)
const announceChannel = true
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,
couponCode: 'SATOSHI_20PERCENT',
lspNodeId: '0296b2db342fcf87ea94d981757fdf4d3e545bd5cef4919f58b5d38dfdd73bf5c9',
})
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: [
{
alias: "Blocktank",
pubkey: "0296b2db342fcf87ea94d981757fdf4d3e545bd5cef4919f58b5d38dfdd73bf5c9",
connectionStrings: [
"0296b2db342fcf87ea94d981757fdf4d3e545bd5cef4919f58b5d38dfdd73bf5c9@146.148.127.140:9735"
]
}
],
options: {
minChannelSizeSat: 1000,
maxChannelSizeSat: 3170000,
minExpiryWeeks: 1,
maxExpiryWeeks: 53,
minPaymentConfirmations: 0,
minHighRiskPaymentConfirmations: 1,
max0ConfClientBalanceSat: 317000,
}
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) {
} else if (errorType === BtChannelOrderErrorType.WRONG_ORDER_STATE) {
} else if (errorType === BtChannelOrderErrorType.CHANNEL_REJECTED_BY_DESTINATION) {
} else if (errorType === BtChannelOrderErrorType.CHANNEL_REJECTED_BY_LSP) {
} else if (errorType === BtChannelOrderErrorType.BLOCKTANK_NOT_READY) {
}
}
throw e
}
Versioning
- Increase version in
package.json
. - Add changes to
CHANGELOG.md
. - Commit changes.
- Tag new version:
git tag v0.1.0
. - Push tag
git push origin v0.1.0
. - Publish to npm:
npm publish
.