Download Bitcoin core and install it whereever you prefer (C:\Bitcoin). It should have daemon, docs and bitcoin-qt with other files. daemon folder contains bitcoind and bitcoin-cli executables.
- We need to run at least two nodes to send/receive transactions. So let us start with first node setup.
- Create 'regtest1' folder at your prefered location (~\AppData\Roaming\Bitcoin).
- Create bitcoin.conf file in this newly created regtest1 folder.
- Add below configurations to this file:
regtest=1
server=1
rpcuser=r1
rpcpassword=r123
fallbackfee=0.0002
[regtest]
port=18445
rpcport=8333
datadir=~\AppData\Roaming\Bitcoin\regtest1
addnode=127.0.0.1:18446
- Open command prompt and run
bitcoind -regtest -datadir=~\AppData\Roaming\Bitcoin\regtest1
to start the first node. - First node is set and running now.
- Create 'regtest2' folder at your prefered location (~\AppData\Roaming\Bitcoin).
- Create bitcoin.conf file in this newly created regtest2 folder.
- Add below configurations to this file:
regtest=1
server=1
rpcuser=r2
rpcpassword=r234
fallbackfee=0.0002
[regtest]
port=18446
rpcport=8334
datadir=~\AppData\Roaming\Bitcoin\regtest2
addnode=127.0.0.1:18445
- Note the difference between rpcuser, rpcpassword, port, rpcport, datadir.
addnode
setting is used to persist the connection between both nodes after restart.fallbackfee
default setting is required for transactions.- Open command prompt and run
bitcoind -regtest -datadir=~\AppData\Roaming\Bitcoin\regtest2
to start the second node. - Second node is set and running now.
- Open two command prompts to execute rpc commands for each node.
- Create one wallet/node with commands:
bitcoin-cli -regtest -rpcport=8333 -rpcuser=r1 -rpcpassword=r123 createwallet wallet1
bitcoin-cli -regtest -rpcport=8334 -rpcuser=r2 -rpcpassword=r234 createwallet wallet2
- Spendable bitcoin are available after minimum 100 blocks are mined. So we will generate 101 blocks to mine our first 50 spendable bitcoins.
- We will use first node to mine these 101 blocks in this example.
- Get new address from first wallet with:
bitcoin-cli -regtest -rpcport=8333 -rpcuser=r1 -rpcpassword=r123 getnewaddress
- Generate 101 blocks on above newly generated address with:
bitcoin-cli -regtest -rpcport=8333 -rpcuser=r1 -rpcpassword=r123 generatetoaddress 101 <getnewaddress-value>
- Note that both bitcoin node shells are showing 101 blocks now.
- Confirm that both nodes have same block count as 101:
bitcoin-cli -regtest -rpcport=8333 -rpcuser=r1 -rpcpassword=r123 getblockcount
bitcoin-cli -regtest -rpcport=8334 -rpcuser=r2 -rpcpassword=r234 getblockcount
- Check wallet balances, wallet1 should have 50 BTC and wallet2 zero at this point.
bitcoin-cli -regtest -rpcport=8333 -rpcuser=r1 -rpcpassword=r123 getwalletinfo
bitcoin-cli -regtest -rpcport=8334 -rpcuser=r2 -rpcpassword=r234 getwalletinfo
- We will send 20 Bitcoins from wallet1 to wallet2
- Get new address from wallet2 where we want to receive funds:
bitcoin-cli -regtest -rpcport=8334 -rpcuser=r2 -rpcpassword=r234 getnewaddress
- Go to wallet1 and send 20 Bitcoins to wallet2's above generated address:
bitcoin-cli -regtest -rpcport=8333 -rpcuser=r1 -rpcpassword=r123 sendtoaddress <getnewaddress-value> 20
- On successful transaction, above command will respond with transaction id. This txid can be found in mempool at this point (Optional Steps down below*).
- Generate 1 more block on node1 with
getnewaddress
&generatetoaddress 1 <getnewaddress-value>
. It will confirm the transaction on blockchain. - Check wallet balances once again to confirm that funds has been transferred from wallet1 to wallet2:
bitcoin-cli -regtest -rpcport=8333 -rpcuser=r1 -rpcpassword=r123 getwalletinfo
bitcoin-cli -regtest -rpcport=8334 -rpcuser=r2 -rpcpassword=r234 getwalletinfo
- Note that wallet1 has 79.99997180 and wallet2 has 20 Bitcoins. Wallet1 has 29.99997180 Bitcoins as change output from last transaction and 50 Bitcoins are mining reward of the last block.
-
To check mempool information:
- Run getmempoolinfo command to see mempool:
bitcoin-cli -regtest -rpcport=8334 -rpcuser=r2 -rpcpassword=r234 getmempoolinfo
- Note that the mempool size is 1 which is our latest transaction and total fee charged is 0.00002820.
-
To check transaction details:
- Get raw transaction information:
bitcoin-cli -regtest -rpcport=8334 -rpcuser=r2 -rpcpassword=r234 getrawtransaction <txid-from-above-transaction>
- Decode the transaction with above received hexstring:
bitcoin-cli -regtest -rpcport=8334 -rpcuser=r2 -rpcpassword=r234 decoderawtransaction <hexstring-from-getrawtransaction>
- Note that the response has one input (vin) of 50 Bitcoins and two outputs (vout) of 20 & 29.99997180 Bitcoins.
-
Install LND:
- Download the latest release from LND's github and unpack it (C:\Nodes\Regtest1LND). It should have lnd & lncli executables.
-
First data folder and configurations:
- Create a folder to contain LND's data, logs, keys, certs, and config file (~\AppData\Local\Lnd-regtest-1).
- Create a config file named lnd.conf inside this newly created folder (~\AppData\Local\Lnd-regtest-1\lnd.conf).
- Add below configuration settings in the file:
[Application Options] alias=shahanaRegtest1 color=#68F450 debuglevel=debug listen=0.0.0.0:9735 restlisten=0.0.0.0:8080 rpclisten=0.0.0.0:10009 datadir=~\AppData\Local\Lnd-regtest-1\data logdir=~\AppData\Local\Lnd-regtest-1\logs tlscertpath=~\AppData\Local\Lnd-regtest-1\tls.cert tlskeypath=~\AppData\Local\Lnd-regtest-1\tls.key [Bitcoin] bitcoin.active=1 bitcoin.regtest=1 bitcoin.node=bitcoind [Bitcoind] bitcoind.rpcuser=r1 bitcoind.rpcpass=r123 bitcoind.rpchost=127.0.0.1:8333 bitcoind.zmqpubrawblock=tcp://127.0.0.1:28334 bitcoind.zmqpubrawtx=tcp://127.0.0.1:28335
-
Run first LND:
- Open command prompt and run
lnd --configfile=~\AppData\Local\Lnd-regtest-1\lnd.conf
. - Note that it created data & logs folders and tls.cert & tls.key files in ~\AppData\Local\Lnd-regtest-1.
- Create a new wallet for LND:
lncli --tlscertpath=~\AppData\Local\Lnd-regtest-1\tls.cert create
- It will create a new LND wallet and macaroons for authentication.
- Wait for some time for the node to sync.
- Verify your node details with
getinfo
command:
lncli --tlscertpath=~\AppData\Local\Lnd-regtest-1\tls.cert --macaroonpath=~\AppData\Local\Lnd-regtest-1\data\chain\bitcoin\regtest\admin.macaroon getinfo
- Open command prompt and run
-
Install LND:
- Download the latest release from LND's github and unpack it (C:\Nodes\Regtest2LND). It should have lnd & lncli executables.
-
Second data folder and configurations:
- Create a folder to contain LND's data, logs, keys, certs, and config file (~\AppData\Local\Lnd-regtest-2).
- Create a config file named lnd.conf inside this newly created folder (~\AppData\Local\Lnd-regtest-2\lnd.conf).
- Add below configuration settings in the file:
[Application Options] alias=shahanaRegtest2 color=#864F05 debuglevel=debug listen=0.0.0.0:9736 restlisten=0.0.0.0:9090 rpclisten=0.0.0.0:10010 datadir=~\AppData\Local\Lnd-regtest-2\data logdir=~\AppData\Local\Lnd-regtest-2\logs tlscertpath=~\AppData\Local\Lnd-regtest-2\tls.cert tlskeypath=~\AppData\Local\Lnd-regtest-2\tls.key [Bitcoin] bitcoin.active=1 bitcoin.regtest=1 bitcoin.node=bitcoind [Bitcoind] bitcoind.rpcuser=r2 bitcoind.rpcpass=r234 bitcoind.rpchost=127.0.0.1:8334 bitcoind.zmqpubrawblock=tcp://127.0.0.1:28336 bitcoind.zmqpubrawtx=tcp://127.0.0.1:28337
-
Run second LND:
- Open command prompt and run
lnd --configfile=~\AppData\Local\Lnd-regtest-2\lnd.conf
. - Note that it created data & logs folders and tls.cert & tls.key files in ~\AppData\Local\Lnd-regtest-2.
- Create a new wallet for LND:
lncli --tlscertpath=~\AppData\Local\Lnd-regtest-2\tls.cert --rpcserver=127.0.0.1:10010 create
- It will create a new LND wallet and macaroons for authentication.
- Wait for some time for the node to sync.
- Verify your node details with
getinfo
command:
lncli --tlscertpath=~\AppData\Local\Lnd-regtest-2\tls.cert --rpcserver=127.0.0.1:10010 --macaroonpath=~\AppData\Local\Lnd-regtest-2\data\chain\bitcoin\regtest\admin.macaroon getinfo
- Open command prompt and run
-
Connect Peers:
- Go to second lncli and connect with first pubkey (pubkey value from first lncli getinfo command):
lncli --tlscertpath=~\AppData\Local\Lnd-regtest-2\tls.cert --rpcserver=127.0.0.1:10010 --macaroonpath=~\AppData\Local\Lnd-regtest-2\data\chain\bitcoin\regtest\admin.macaroon connect <first-wallet-pubkey>@localhost:9735
- Connection can be verified with
listpeers
command.
-
Receive Bitcoins:
- Send some bitcoins from bitcoin wallets to these newly created LND wallets (Use RTL's onchain => generate address and run bitcoin-cli's
sendtoaddress
for sending bitcoins to these addresses. - Generate 1 block for transfers to both wallets to be confirmed.
- Send some bitcoins from bitcoin wallets to these newly created LND wallets (Use RTL's onchain => generate address and run bitcoin-cli's
-
Open Channel:
- Run open channel command with mandatory information (RTL can be used to do so).
- Generate 4 more blocks for changing channel's status from pending to confirmed.