Electrum X

Time: 15 minutes and 7 days waiting for synchronization/indexing

Using Electrum X, you can use the Electrum protocol. This protocol lets wallets and other software communicate with nodes. In other places in the guide, you can connect tools and wallets that communicate via the Electrum protocol directly to your node. A functionality that promotes privacy. For example, you can also connect the BTC RPC Explorer to your own Electrum X server. Then when you look up information about your transactions or addresses from yourself in the future, no one will be able to see it. This way no one can link transactions to you and you enjoy more privacy.

It can take up to 7 days before Electrum X is fully indexed and usable. Until then you can't use it.

Installation

Make sure you are in the home directory.

cd ~

Install the following packages on your Raspberry.

sudo apt install python3-pip build-essential libc6-dev libncurses5-dev libncursesw5-dev libreadline-dev libleveldb-dev

Using pip you can install a Python-specific package needed for Electrum X.

sudo pip3 install plyvel

Clone the source code for Electrum X.

git clone https://github.com/spesmilo/electrumx

Navigate the directory you just cloned into.

cd electrumx

Grab the latest version.

git checkout 1.16.0

Finally, install Electrum X.

sudo python3 setup.py install

Configuration

As with all the other tools in this guide, you can configure Electrum X in some way. First, we provide a location where the database of Electrum X is stored. Then we create keys using openssl. Finally, we configure Electrum X using a configuration file.

Create an .electrumx folder in the home directory containing another db folder.

mkdir ~/.electrumx
mkdir ~/.electrumx/db

Enter the directory.

cd ~/.electrumx

Run the following three openssl commands to create a set of keys and certificates. During this process you will need to enter some information, but you will see that.

openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 1825 -in server.csr -signkey server.key -out server.crt

The final step of configuring involves creating the configuration file. Create a file.

nano ~/.electrumx/electrumx.conf

Put the following text in there.

NET=mainnet
COIN=Bitcoin
CACHE_MB=500
DB_ENGINE=leveldb
DB_DIRECTORY=/home/ubuntu/.electrumx/db
DAEMON_URL=http://USERNAME:PASSWORD@127.0.0.1
SSL_CERTFILE=/home/ubuntu/.electrumx/server.crt
SSL_KEYFILE=/home/ubuntu/.electrumx/server.key
SERVICES=tcp://:50001,ssl://:50002,wss://:50004,rpc://

Before you save it, you need to make two adjustments. In the USERNAME and PASSWORD places, enter the username-password combination you created in the authentication part of the Bitcoin Core configuration. Once everything is correct you can save the file with Ctrl + X and confirm with Y.

Firewall and Router

In principle, you can connect a local tool such as BTC RPC Explorer directly to Electrum X. There is no need to open any ports for this, as local connections are always allowed (i.e. from the Pi to the Pi). However, if you want to use Electrum X in an app like BlueWallet, you need to execute the following commands to open two ports.

sudo ufw allow 50001
sudo ufw allow 50002

If you want to use Electrum X as a backend from outside your network, then you need to throw the same ports open on your router and loop through to your Pi.

Automation

Electrum X is something you always want to have running in the background. That's why we're going to automate startup through a service. Create a service.

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

Put the following text in there.

[Unit]
Description=Electrum X Server
Requires=bitcoind.service
After=network.target
[Service]
User=ubuntu
EnvironmentFile=/home/ubuntu/.electrumx/electrumx.conf
ExecStart=/usr/local/bin/electrumx_server
Restart=always
TimeoutSec=120
RestartSec=30
[Install]
WantedBy=multi-user.target

Save it with Ctrl + X and confirm with Y.

Enable and start the service with these two commands:

sudo systemctl enable electrumx
sudo systemctl start electrumx

After about a minute of starting up, you can ask Electrum X for some information.

electrumx_rpc getinfo

If your output looks like the one below you are done!

{
"coin": "bitcoin"
"daemon": "127.0.0.1:8332/"
"daemon height": 662952,
"db height": 662952,
"db_flush_count": 5797,
"groups": 0,
"history cache": "0 lookups 0 hits 0 entries",
"merkle cache": "0 lookups 0 hits 0 entries",
"peers": {
"bad": 14,
"good": 83,
"never": 14,
"stale": 7,
"total": 118
},
"pid": 12650,
"request counts": {
"blockchain.block.header": 1,
"blockchain.headers.subscribe": 560,
"getinfo": 1,
"server.features": 560,
"server.peers.subscribe": 560,
"server.version": 560
},
"request total": 2242,
"sessions": {
"count": 1,
"count with subs": 0,
"errors": 0,
"logged": 0,
"pending requests": 1,
"subs": 0
},
"tx hashes cache": "0 lookups 0 hits 0 entries",
"txs sent": 0,
"uptime": "21d 01h 08m",
"version": "ElectrumX 1.16.0"
}

Updating

Stop the Electrum X service.

sudo systemctl stop electrumx

Go to the application directory.

cd ~/electrumx

Update the repository with the latest changes via Git.

git fetch --all

Show the latest version/tag/release.

git describe --tags `git rev-list --tags --max-count=1`

Retrieve the changes from the latest release.

git checkout <OUTPUT FROM PREVIOUS STEP> # for example 1.16.0

Install the software.

sudo python3 setup.py install

Start the Electrum X service.

sudo systemctl start electrumx

Electrum X is now updated!