alexbosworth / ln-service

Node.js interface to LND
MIT License
318 stars 61 forks source link

Can't connect to Lnd using gRPC #151

Closed RastaAlex closed 2 years ago

RastaAlex commented 2 years ago

Hi, I am new to using Lnd and I have problem with connecting to Lnd by using gRPC.

a version of lnd: 0.14.2-beta launch station: Docker

When I try to connect lnd i received this problem:

503,FailedToConnectToDaemon

I linked two containers and can ping them with each other. Default ports are exposed as 8003: 10009, 8004:9735 I can work directly from lncli and everything works well but i can't connect from outside in any way

index.js

import lnService from 'ln-service'

const { lnd } = lnService.authenticatedLndGrpc({
cert: 'base64 -w0 ~/.lnd/tls.cert'
macaroon: 'base64 -w0 ~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon'
socket: 'lnd:10009'
)}

const nodePublicKey = (await lnService.getWalletInfo({ lnd })).public_key
console.log(nodePublicKey )

start-lnd.sh

exec lnd \
    --noseedbackup \
    "--$CHAIN.active" \
    "--$CHAIN.$NETWORK" \
    "--$CHAIN.node"="$BACKEND" \
    "--$BACKEND.rpccert"="/rpc/rpc.cert" \
    "--$BACKEND.rpchost"="blockchain" \
    "--$BACKEND.rpcuser"="$RPCUSER" \
    "--$BACKEND.rpcpass"="$RPCPASS" \
    "--rpclisten=0.0.0.0:10009" \
    "--tlsextraip=0.0.0.0" \
    --debuglevel="$DEBUG" \
    "$@"

docker-compose.yml

lnd:
    image: lnd
    container_name: lnd
    networks:
      - bridge
    ports:
      - 8004:9735
      - 8003:10009
    volumes:
      - shared:/rpc
      - lnd:/root/.lnd
    build:
      context: docker/lnd/
      dockerfile: lnd.Dockerfile
    environment:
      RPCUSER: $BTCD_RPC_USER
      RPCPASS: $BTCD_RPC_PASSWORD
      NETWORK: $BITCOIN_NETWORK
    entrypoint: ["./start-lnd.sh"]
    links:
      - "btcd:blockchain"
alexbosworth commented 2 years ago

I think the tlsextraip has to be accurate

Here is an example docker spawn LND https://github.com/alexbosworth/ln-docker-daemons/blob/master/lnd/spawn_lnd_docker.js

RastaAlex commented 2 years ago

@alexbosworth thank's for your reply. I want to connect to my Lnd container from another and the container changes IP every time after the start. Tls cert does not allow us to connect. Do you know what are the best practices: -update tls cert every time -Lnd proxy(8080). Unfortunately can't find docs -static IP for our container and include it into tls cert -external proxy

alexbosworth commented 2 years ago

I'm not sure what the best practice is, but docker does have an API itself

RastaAlex commented 2 years ago

The main problem is that I did not write correctly in tlsextraip. @alexbosworth thanks for the help.