Running simnet in LND
We are going to run a bitcoin node and a lightning node in simnet, it means that we will create a simulation network that is totally under our control, so we can create blocks at will and therefore we do not have to wait.
Create the NETWORK variable to use simnet:
export NETWORK="simnet"
Run the container to use lnd with btcd, and give a name to it. Below we are setting the name "alice" to this container. But you can use other one.
docker-compose run -d --name alice lnd_btc
Log into the container:
docker exec -i -t alice bash
Once you are inside the container you can get information about the state of the network.
lncli --network=simnet getinfo
Create a new address:
lncli --network=simnet newaddress np2wkh
It will generate an output as below, of course with different address:
{
"address": "rW4ebXj96Yd2AVNjpRgURKvAz8JfgNWjKt"
}
Then outside of the container we recreate "btcd" node and set the generated address as mining address:
MINING_ADDRESS=<your_address> docker-compose up -d btcd
Generate 400 blocks (we need at least "100 >=" blocks because of coinbase block maturity and "300 ~=" in order to activate segwit):
docker-compose run btcctl generate 400
Now you can check that segwit is active:
docker-compose run btcctl getblockchaininfo | grep -A 1 segwit
LND uses macaroons as authentication, they are like cookies with more functionality.
Copy the admin.macaroon
file from lnd docker to your filesystem.
docker cp alice:/root/.lnd/data/chain/bitcoin/simnet/admin.macaroon ~/<your-prefered-path>
Then you need to find the IP where your container is running. You do it by running the command below:
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' alice
It will return something like:
172.18.0.3
Once we have the IP and the admin.macaroon
file, we can comunicate with lnd using curl using lnd-rest.
-
getinfo
curl -X GET --insecure -i "Grpc-Metadata-macaroon: $(xxd -ps -u -c 1000 ~/admin.macaroon)" https://172.18.0.3:8001/v1/getinfo
-
generate an invoice
curl -X POST --insecure --header "Grpc-Metadata-macaroon: $(xxd -ps -u -c 1000 ~/admin.macaroon)" --data '{"expiry":"144","value":"1000"}' https://172.19.0.3:8001/v1/invoices