# lnd
## Docs
### [[REST]] API
- https://api.lightning.community/#lnd-rest-api-reference
- https://github.com/lightningnetwork/lnd/blob/4337116bce2cf2fd3b306d84b09885d0a6df0320/lnrpc/lightning.swagger.json
## Libraries
### Rust bindings by LightningPeach
https://github.com/LightningPeach/lnd-rust
https://crates.io/crates/lnd-rust
(no docs)
Last updated two years ago, could probably use some maintenance
- Docs says it works with LND 0.5.0
- LND is currently on 0.13 (as of July 2021)
### [[Node.js]] [[gRPC]] interface
by [[Alex Bosworth]]
https://github.com/alexbosworth/ln-service
### [[tonic]] [[gRPC]] interface
https://github.com/Kixunil/tonic_lnd
- Has 4k LOC but only two commits
## Installation
### Onboarding scripts
https://docs.lightning.engineering/lightning-network-tools/lnd/get-started-with-lnd#installing-lnd-using-third-party-scripts
- [[BTCPay]] Server: https://btcpayserver.org/
- [[RaspbiBlitz]]: https://raspiblitz.org/
- [[Umbrel]]
### Installation Methods
- From binary releases
- Install via [[Docker]]
## Usage
### Auto-unlocking a wallet
(This is insecure; for development purposes only)
Follow the directions here: https://github.com/lightningnetwork/lnd/blob/master/docs/wallet.md#auto-unlocking-a-wallet
Additional notes:
- Shut down [[lnd]] first before doing this
- Adding the [Bitcoin] or [Application Options] headers generates an error, just go without
- `lnd.conf` does not accept quotes in parameter names, just include the space directly and don't escape it, like so:
`lnd.conf`
```text
wallet-unlock-password-file=/Users/fang/Library/Application Support/Lnd/password.txt
```
### Minimal [[REST]] code
Minimal working Python code:
```python
import base64, codecs, json, requests
host = "http://max.ngrok.io"
# host = "https://localhost:8080"
endpoint = "/v1/getinfo"
url = "{}{}".format(host, endpoint)
cert = "/Users/fang/Library/Application Support/Lnd/tls.cert"
# macaroon = codecs.encode(open(
# '/Users/fang/Library/Application Support/Lnd/data/chain/bitcoin/simnet/admin.macaroon',
# 'rb'
# ).read(), 'hex')
# headers = {'Grpc-Metedata-macaroon': macaroon}
headers = {}
print("Requesting {}".format(url))
response = requests.get(url, headers=headers, verify=cert)
print("Response: {}".format(response))
print("Response json: {}".format(response.json()))
```
- Also works with [[ngrok]]: see [[ngrok#Tunnel to https localhost port]]
### [[gRPC]]
Setup instructions here:
https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md
- The `googleapis/googleapis` step is not needed as `annotations.proto` is not actually used
Minimal working [[Python]] code:
```python
import lightning_pb2 as ln
import lightning_pb2_grpc as lnrpc
import grpc
import os
# Due to updated ECDSA generated tls.cert we need to let gprc know that
# we need to use that cipher suite otherwise there will be a handhsake
# error when we communicate with the lnd rpc server.
os.environ["GRPC_SSL_CIPHER_SUITES"] = 'HIGH+ECDSA'
# Lnd cert is at ~/.lnd/tls.cert on Linux and
# ~/Library/Application Support/Lnd/tls.cert on Mac
cert = open(
os.path.expanduser('/Users/fang/Library/Application Support/Lnd/tls.cert'),
'rb'
).read()
creds = grpc.ssl_channel_credentials(cert)
channel = grpc.secure_channel('localhost:10009', creds)
# channel = grpc.secure_channel('https://max.ngrok.io', creds)
stub = lnrpc.LightningStub(channel)
# Simple RPC
response = stub.WalletBalance(ln.WalletBalanceRequest())
print(response.total_balance)
response = stub.ChannelBalance(ln.ChannelBalanceRequest())
print(response)
```
## Debugging
### "verification failed: signature mismatch after caveat verification"
Appears to be a problem with macaroons
- https://github.com/lightningnetwork/lnd/issues/1796
- https://github.com/rootzoll/raspiblitz/issues/409
Macaroons are stored at e.g. `~/.lnd/data/chain/bitcoin/simnet/admin.macaroon`
- https://github.com/lightningnetwork/lnd/blob/master/sample-lnd.conf#L99
Simple solution acceptable for test environments is to set `no-macaroons=true` in `lnd.conf`