DEV Community

Kofi Oghenerukevwe H.
Kofi Oghenerukevwe H.

Posted on

Minimal Deployment of BTCPayServer in Testnet Mode with Electrum Wallet

BTCPay Server is a self-hosted opensource solution for receiving Bitcoin and Altcoin payments. BTCPay Server implements the same API as Bitpay so it's easy to switch over from one to the other. There are detailed instructions for setting up the BTCPay Server (for a production environment) on the BTCPay Server documentation available here: BTCPay Server docs. That said, a minimal setup of BTCPay server in testnet mode is a bit tricky and this post is here to document the steps I took when I had to do that a few weeks ago. To be clear The instructions in this post are not for setting BTCPay Server up in production. For production settings, see BTCPay Server's official documentation

The notes here are just to supplement the Minimal Manual Deployment docs on BTCPay Server which can be found here Minimal Manual Deployment

Install Bitcoin

Using these commands

BITCOIN_VERSION="0.19.1"
BITCOIN_URL="https://bitcoin.org/bin/bitcoin-core-0.19.1/bitcoin-0.19.1-x86_64-linux-gnu.tar.gz"
BITCOIN_SHA256="5fcac9416e486d4960e1a946145566350ca670f9aaba99de6542080851122e4c"

# install bitcoin binaries
cd /tmp
wget -O bitcoin.tar.gz "$BITCOIN_URL"
echo "$BITCOIN_SHA256 bitcoin.tar.gz" | sha256sum -c - && \
mkdir bin && \
sudo tar -xzvf bitcoin.tar.gz -C /usr/local/bin --strip-components=2 "bitcoin-$BITCOIN_VERSION/bin/bitcoin-cli" "bitcoin-$BITCOIN_VERSION/bin/bitcoind"
rm bitcoin.tar.gz
Enter fullscreen mode Exit fullscreen mode

Install .NET Core

wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install -y dotnet-sdk-3.1
Enter fullscreen mode Exit fullscreen mode

Install NBXplorer

cd ~
git clone https://github.com/dgarage/NBXplorer
cd NBXplorer
git checkout latest
./build.sh
Enter fullscreen mode Exit fullscreen mode

Install Electrum

You can use Electrum to setup either a testnet or live wallet for use with BTCPay Server.

Install Electrum with any of the steps available on their docs Electrum Installation Docs

Install BTCPayServer

cd ~
git clone https://github.com/btcpayserver/btcpayserver
cd btcpayserver
git checkout latest
./build.sh
Enter fullscreen mode Exit fullscreen mode

Long-running processes

A quick note that Bitcoin, NBXplorer and BTCPay are long running processes that should ideally run in the background. So when you run bitcoind for instance, it would take over your ssh session till you stop the process. If you don't want to run them in the background, you can consider using something like tmux to manage different sessions if you plan on just running these commands and leaving them running in multiple windows of the same ssh session.

# create a new session with
tmux new -s BTC

# create a new window in a session with Ctrl + b, c
# detach from session with Ctrl + b, d
# re-attach to session with tmux attach-session -t BTC
Enter fullscreen mode Exit fullscreen mode

Run Bitcoin in Testnet and Background Mode

To run Bitcoind in testnet mode

bitcoind -testnet
Enter fullscreen mode Exit fullscreen mode

Run in the background using

bitciond -daemon -testnet
Enter fullscreen mode Exit fullscreen mode

Run NBXplorer in testnet mode

cd ~/NBXplorer
./run.sh --chains=btc --network=testnet
Enter fullscreen mode Exit fullscreen mode

Setup your testnet wallet with Electrum

# start testnet electrum in the background
electrum daemon -d --testnet 

# create a main wallet
electrum create --testnet 

# load wallet
electrum load_wallet --testnet

# get the master key of the wallet - you'll need this for your BTCPayServer store
electrum getmpk --testnet
Enter fullscreen mode Exit fullscreen mode

Run BTCPay Server in testnet mode

cd ~/btcpayserver
./run.sh --network=testnet --bind=0.0.0.0 --port=8080 --sqlitefile=mydb.db --chains=btc
Enter fullscreen mode Exit fullscreen mode

Unless you're using Tor, you might need to setup a server like Apache or Nginx with an ssl certificate that forwards to BTCPay server on port 8080 because BTCPay server does needs you to access it through HTTPS

Setup your BTCPay Server store.

After BTCPay Server is launched, visit it at its url and create a store. Then integrate that store with your electrum Bitcoin wallet using the master key you got from Electrum earlier.

See Connect BTCPay Server Wallet in the BTCPay Server docs.

Top comments (0)