Skip to main content

This is a fork with minor changes from

https://github.com/kornpow/lnd-grpc-client

for my own data project. The name of the forked package at pypi.org is fl21-lnd-grpc-client.


lnd-grpc-client

A python grpc client for LND (Lightning Network Daemon) ⚡⚡⚡

This is a wrapper around the default grpc interface that handles setting up credentials (including macaroons). An async client is also available to do fun async stuff like listening for invoices in the background.

Dependencies

  • Python 3.6+
  • Working LND lightning node, take note of its ip address.
  • Copy your admin.macaroon and tls.cert files from your node to a directory on your machine.

Installation

pip install lnd-grpc-client

CLI Usage

This package adds a CLI command to your PATH once installed:

lndgrpcclient_cli

Setup

$ lndgrpcclient_cli environment

Saving credentials!
Enter your node's IP Address [127.0.0.1]: 86.75.309.69
86.75.309.69
Enter your node's Port [10009]: 
10009
Enter your node's Alias [default-node-alias]: my-cool-node
my-cool-node
Where do you want keep your node credentials? Macaroons and tls.cert? [/home/kornpow/Documents/lnd-creds/my-cool-node]: 
Enter your macaroon filename [admin.macaroon]: 
Build directory structure and save `node-env` file at location: /home/kornpow/Documents/lnd-creds/my-cool-node [True]: 1
This environment file must be loaded to access your node!

export LND_CRED_PATH=/home/kornpow/Documents/lnd-creds/my-cool-node
export LND_NODE_IP=86.75.309.69
export LND_NODE_PORT=10009
export LND_MACAROON=admin.macaroon
Writing file....
Wrote environment file to location: /home/kornpow/Documents/lnd-creds/my-cool-node/node-env
Enable it by running: source /home/kornpow/Documents/lnd-creds/my-cool-node/node-env
$ lndgrpcclient_cli credentials --input_format hex --credential_type macaroon

Saving credentials to: /home/kornpow/Documents/lnd-creds/my-cool-node
Enter your node's macaroon []: abcdef123456
Enter your macaroon name: [admin]: readonly
Enable this macaroon by running:
 export LND_MACAROON=readonly.macaroon
Wrote file: /home/kornpow/Documents/lnd-creds/my-cool-node/readonly.macaroon
$ lndgrpcclient_cli credentials --input_format hex --credential_type tls

Saving credentials to: /home/kornpow/Documents/lnd-creds/my-cool-node
Enter your node's tls []: abcdef1234
Wrote file: /home/kornpow/Documents/lnd-creds/my-cool-node/tls.cert

Usage

$ lndgrpcclient_cli shell

>>> lnd.get_info().block_hash
'0000000000000000000873876975b2443cfcb93cd9b66c58ed6da922fe5f40b3'

>>> lnd.get_node_info("0360a41eb8c3fe09782ef6c984acbb003b0e1ebc4fe10ae01bab0e80d76618c8f4").node.alias
'kungmeow'

>>> lnd.get_network_info()
graph_diameter: 13
avg_out_degree: 5.528722661077973
max_out_degree: 417
num_nodes: 18609
num_channels: 51442
total_network_capacity: 2873600
avg_channel_size: 55.86096963570623
max_channel_size: 1000000
num_zombie_chans: 165176

Advanced Usage

Go in the examples folder for some advanced examples including:

  • Open channel using PSBT: openchannel-external.py
  • Open Batch of Channels using PSBT: batchopenchannel-external.py
  • Keysend Payments: send-keysend.py
  • Reconnect to your peers: reconnect-peers.py
  • Channel Acceptor API w/ a custom failure message: channel-acceptor.py

Async

import asyncio
from lndgrpc import AsyncLNDClient

async_lnd = AsyncLNDClient()

async def subscribe_invoices():
    print('Listening for invoices...')
    async for invoice in async_lnd.subscribe_invoices():
        print(invoice)

async def get_info():
    while True:
        info = await async_lnd.get_info()
        print(info)
        await asyncio.sleep(5)

async def run():
    coros = [subscribe_invoices(), get_info()]
    await asyncio.gather(*coros)

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

Specifying Macaroon/Cert files

By default the client will attempt to lookup the readonly.macaron and tls.cert files in the mainnet directory. However if you want to specify a different macaroon or different path you can pass in the filepath explicitly.

lnd = LNDClient(
    macaroon_filepath='~/.lnd/invoice.macaroon', 
    cert_filepath='path/to/tls.cert'
)

Generating LND Proto Files

mkvirtualenv gen_rpc_protos
# or 
workon gen_rpc_protos
# then

pip install grpcio grpcio-tools googleapis-common-protos sh

cd lndgrpc
git clone --depth 1 https://github.com/googleapis/googleapis.git
cd ..

Set environment variables

export APP_DIR=$HOME/Documents/lightning/lnd
export CLIENT_DIR=$HOME/Documents/lightning/lnd-grpc-client
python3 rebuild_protos.py

Deploy to Test-PyPi

poetry build
twine check dist/*
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
```howdy

Metadata

Release files for fl21-lnd-grpc-client 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fl21-lnd-grpc-client 0.6.0
File Size Uploaded Provenance Actions
fl21_lnd_grpc_client-0.6.0.tar.gz 183.8 kB Without provenance Details for fl21_lnd_grpc_client-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fl21-lnd-grpc-client 0.6.0
File Interpreter ABI Platform Actions
fl21_lnd_grpc_client-0.6.0-py3-none-any.whl Python 3 none any Details for fl21_lnd_grpc_client-0.6.0-py3-none-any.whl

Total release size: 399.3 kB

Release files / fl21_lnd_grpc_client-0.6.0.tar.gz

Download URL fl21_lnd_grpc_client-0.6.0.tar.gz
Size 183.8 kB
Tags Source
SHA-256 checksum
How to use checksums
59cf2d9a0c951c47c6c1cf34bd1522f5807c61fdf591863f1ef12390fc22829e
BLAKE2b-256 checksum
How to use checksums
4a68ad3ac6684a51d15ec5d3889bb0e040a94909fd5d26593221a3ca39d70517
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / fl21_lnd_grpc_client-0.6.0-py3-none-any.whl

Download URL fl21_lnd_grpc_client-0.6.0-py3-none-any.whl
Size 215.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc5247cd1902de4dcd03ad84fe004f6dee1747f3ba61e5192e897595bb9c0344
BLAKE2b-256 checksum
How to use checksums
3e3f5da4bc6bb600195ed209c8b5c5ed7018a2b9621f4103207ec1b92ee8bdc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Security for fl21-lnd-grpc-client 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page