@radar/lnrpc
A Typescript gRPC client for LND with support for all LND sub-servers. Originally forked from Matt-Jensen/lnrpc. Forked again from RadarTech/lnrpc to migrate from the soon to be deprecated grpc
package to grpc-js
.
Features
- Auto-generates lnd/lnrpc clients and Typescript type definitions using a target release tag
- Supports all LND sub-servers
- Wraps requests in promises
- Easily setup SSL and Macaroons
- Instantiates all gRPC services
- uint64/int64 types cast to string to prevent precision loss
Installation
npm install @jamaljsr/lnrpc
yarn add @jamaljsr/lnrpc
Notes:
Usage
This package exports a create function for the main gRPC server as well as each sub-server:
import {
createAutopilotRpc,
createChainRpc,
createInvoicesRpc,
createLnRpc,
createRouterRpc,
createSignRpc,
createWalletRpc,
createWatchtowerRpc,
createWtClientRpc,
} from '@radar/lnrpc';
You can also import the create function for the main gRPC server using the default import:
import createLnRpc from '@radar/lnrpc';
If you want to interact with all servers, wrap the functions in a class or object for easy initialization:
import createLnRpc, {
AutopilotRpc,
ChainRpc,
createAutopilotRpc,
createChainRpc,
createInvoicesRpc,
createRouterRpc,
createSignRpc,
createWalletRpc,
createWatchtowerRpc,
createWtClientRpc,
InvoicesRpc,
LnRpc,
RouterRpc,
RpcClientConfig,
SignRpc,
WalletRpc,
WatchtowerRpc,
WtClientRpc,
} from '@radar/lnrpc';
export class Lightning {
public static lnrpc: LnRpc;
public static autopilotrpc: AutopilotRpc;
public static chainrpc: ChainRpc;
public static invoicesrpc: InvoicesRpc;
public static routerrpc: RouterRpc;
public static signrpc: SignRpc;
public static walletrpc: WalletRpc;
public static watchtowerrpc: WatchtowerRpc;
public static wtclientrpc: WtClientRpc;
public static async init(config: RpcClientConfig): Promise<void> {
this.lnrpc = await createLnRpc(config);
this.autopilotrpc = await createAutopilotRpc(config);
this.chainrpc = await createChainRpc(config);
this.invoicesrpc = await createInvoicesRpc(config);
this.routerrpc = await createRouterRpc(config);
this.signrpc = await createSignRpc(config);
this.walletrpc = await createWalletRpc(config);
this.watchtowerrpc = await createWatchtowerRpc(config);
this.wtclientrpc = await createWtClientRpc(config);
}
}
Usage Example - Main Server
Connecting to an lnd instance at localhost:10001
.
import createLnRpc from '@radar/lnrpc';
(async () => {
const lnRpcClient = await createLnRpc(config);
const { confirmedBalance } = await lnRpcClient.walletBalance();
console.log(confirmedBalance);
const subscriber = await lnRpcClient.subscribeInvoices();
subscriber.on('data', invoice => {
console.log(invoice);
});
})();
Options Example - Main Server
import createLnRpc from '@radar/lnrpc';
(async () => {
const lnRpcClient = await createLnRpc({
server: '173.239.209.2:3001',
tls: './path/to/tls.cert',
cert: process.env.MY_SSL_CERT,
macaroonPath: './path/to/data/admin.macaroon',
macaroon: process.env.MY_MACAROON_HEX,
});
try {
const getInfoResponse = await lnRpcClient.getInfo();
console.log(getInfoResponse);
} catch (error) {
console.error(error);
}
})();
API Reference
All main server (lnrpc) methods documentation can be found here.
Usage With BTCPayServer
By default lnrpc assumes SSl certificate pinning.
In order to use lnrpc with a service (like BTCPayServer) which manages your certification,
you'll have to opt to disable certificate pinning by passing { tls: false }
within your lnrpc configuration.
Contributing
Clone Repository & Install Dependencies
git clone git@github.com:RadarTech/lnrpc.git && cd $_
npm install
yarn
Change LND gRPC release version
To change the gRPC definitions used for all auto-generated types and RPC methods edit the config.lnd_release_tag
value in package.json
to the desired LND release tag and run the following:
npm run update-protos
yarn update-protos
npm run generate
yarn generate
Newly generated type definitions will be available in ./generated
.
You can now delete the old proto file inside the lnd directory.
Use the generated type definitions to update the types in src/types/rpc
.
Any added streaming methods must be included in the subscriptionMethods
array that's into the createServiceClient
function.
This prevents streaming methods from being promisified.
License
This project is licensed under the MIT License.