Electrum Personal Server

Time: 30 minutes

If you are using Electrum's wallet software, a logical step is to ensure that Electrum talks to your own node. This cannot be done directly but has to be done through an Electrum Server. This is because the Electrum wallet software normally connects to Electrum Servers of which you don't know who is tracking their use. The Electrum server keeps track of the addresses you have received Bitcoin from and this way several addresses can be traced back to your IP. You don't want that to happen. The solution: run your own Electrum Server. There are several forks available such as ElectrumX, ElectRS and Electrum Personal Server. This document describes the installation of Electrum Personal Server because it is currently the most lightweight implementation. TRTN also includes a guide to installing for ElectrumX. You don't need both so think about which fork you need in advance. One advantage of EPS is that it is quite light and simple. A disadvantage is that it only allows 1 connection at a time. This can be a disadvantage if at a later time you might want to connect to both a desktop client and Blue Wallet at the same time.

Preparations

SSH into your Pi and run the install command for the necessary tools.

sudo apt install -y python3 python3-pip
sudo pip3 install setuptools

Check that in bitcoin.conf there is a line disablewallet = 0.

nano /home/ubuntu/.bitcoin/bitcoin.conf

If it is not there already, add it, save the file (using Ctrl + X) and restart the bitcoind service.

sudo systemctl restart bitcoind

EPS needs a wallet in Bitcoin Core. Create one if it is not already present. From bitcoin version 23.0 the default wallet type created is descriptor, which does not support importing adresses. To prevent this you need to add descriptors=false

bitcoin-cli -named createwallet wallet_name="electrumpersonalserver" disable_private_keys=true descriptors=false

Finally, create the following folder in your homedir and go into it.

cd ~
mkdir .eps
cd .eps

Installation

Now we can proceed to download the source and install Electrum Personal Server. Make sure you have the most recent version of EPS.

From the Github, download the latest release of Electrum Personal Server. Copy the link from Source code (tar.gz), unzip it and discard the download.

wget https://github.com/chris-belcher/electrum-personal-server/archive/eps-v0.2.4.tar.gz
tar -xvf eps-v0.2.4.tar.gz
rm eps-v0.2.4.tar.gz

Make a copy of the configuration file and modify it.

cp electrum-personal-server-eps-v0.2.4/config.ini_sample config.cfg
nano config.cfg

This config-file contains a lot of comments and tips on what to enter where. In any case, take a look at the following sections:

  • [master-public-keys] - in Electrum, look up your xpub via the Wallet > Information menu.
  • [bitcoin-rpc] - datadir = /home/ubuntu/.bitcoin
  • [electrum-server] - here choose host = 0.0.0.0 (instead of 127.0.0.1)
  • wallet_filename - make this wallet_filename = electrumpersonalserver if you have previously created a special wallet for this. Or enter wallet.dat here if you are using the default wallet from Bitcoin Core so that it is clear to EPS which wallet file to use. If you want to use Specter later on, it will also create wallets and if you did not specify a wallet_filename, EPS will not start.

For the last command in the block below, pay attention to the dot at the end of the line

cd electrum-personal-server-eps-v0.2.4
pip3 install wheel
pip3 install use .

Startup

Electrum Personal Server is now installed (in ~/.local/bin) and ready to be started for the first time. You invoke it by also providing the path to the config file. This may take ~10 minutes. After that, the program will stop.

~/.local/bin/electrum-personal-server ~/.eps/config.cfg

Now EPS should scan the blockchain looking for addresses and transactions belonging to the xpubs you included in the config.cfg. If you are asked for the start date, it is useful that you give the date of the first transaction to an address belonging to that wallet. Then EPS does not need to scan blocks that do not contain transactions belonging to your xpub.

~/.local/bin/electrum-personal-server --rescan ~/.eps/config.cfg

You can monitor the progress by keeping an eye on bitcoin's log file through a second Putty window:

sudo tail -f -n 200 /home/ubuntu/.bitcoin/debug.log

When it is finished start EPS again.

~/.local/bin/electrum-personal-server ~/.eps/config.cfg

Automation

Now we just need to make sure the EPS starts running as a Service. You should have two windows open. One with the output of the bitcoin log and one where EPS is running.

sudo nano /etc/systemd/system/eps.service

Paste:

[Unit]
Description=Electrum Personal Server
Requires=bitcoind.service
After=bitcoind.service
[Service]
ExecStart=/usr/bin/python3 /home/ubuntu/.local/bin/electrum-personal-server /home/ubuntu/.eps/config.cfg
User=ubuntu
Group=ubuntu
Type=simple
KillMode=process
TimeoutSec=60
Restart=always
RestartSec=60
[Install]
WantedBy=multi-user.target

Close the file and save the changes. Next, enable and start the service.

sudo systemctl enable eps
sudo systemctl start eps

You can follow the progress of EPS startup by viewing the log file:

sudo tail -f -n 200 /tmp/electrumpersonalserver.log

Firewall

Again, the firewall needs to be updated. The port over which Electrum Personal Server shows up is 50002.

sudo ufw allow 50002

Electrum Wallet

  1. Now start Electrum Wallet on your PC with "C:\Program Files (x86)\Electrum\electrum-4.1.5.exe" --server PI-IP-ADDRESS:50002:s --oneserver
  2. From the Tools menu, choose Network
  3. Open the Server tab
  4. Uncheck the box next to "select server automatically".
  5. At server, enter the IP address of your RPi4
  6. Click on Close

If all went well, you will have a green circle in the lower right corner of the Electrum window indicating that you are connected. You can also

  1. From the View menu, choose Show Console
  2. Click on the Console tab

Here you will now see that you are connected to an EPS and your Bitcoin Node!

Updating

Stop the service.

sudo systemctl stop eps

From the Github, download the tarball of the latest release of Electrum Personal Server. Copy the link from source code (tar.gz), unzip it and discard the download. Replace the version numbers here with the most recent, of course.

cd ~/.eps
wget https://github.com/chris-belcher/electrum-personal-server/archive/eps-v0.2.4.tar.gz
tar -xvf eps-v0.2.4.tar.gz
rm eps-v0.2.4.tar.gz
cd electrum-personal-server-eps-v0.2.4
pip3 install use .

Start the service again.

sudo systemctl start eps