Electrum is a lightweight Bitcoin wallet. Electrum focuses on speed, with low resource usage and simplification of Bitcoin. Its startup time is fast because it runs in conjunction with the Electrum Server which handles the most complex parts of the Bitcoin system. The Electrum Server is run by volunteers across the Internet.
This article explains how to set up an Electrum Server that can be accessed via IPv4, IPv6, and as a Hidden Service over the Tor network. In this article we use an Ubuntu System to run the Electrum Server and Bitcoin.
Storage Space
The Electrum database needs another 17 GB of storage, additionally to the ~ 40 GB of a Bitcoin Node.
To check the available free space of the disk who will hold the Electrum database:
runtu@runtu-desktop:~$ sudo df -h /var/lib
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/server--vg-root 456G 102G 331G 24% /
Bitcoin Full Node
The Electrum Server relies on a installed and running Bitcoin Full Node. The bitcoin node should have processed all blocks and caught up to the current height of the network. The Electrum server needs to be able to communicate with the Bitcoin node trough RPC.
Additionally the Bitcoin Node needs to maintain a full index of historical transaction IDs, a feature which is not enabled by default. To enabled this, the following line needs to be added to the Bitcoin configuration file /etc/bitcoin/bitcoin.conf:
# Required for Electrum Server Bitcoin
txindex=1
Don’t forget to re-adjust the file ownership if it was edited by the root user:
runtu@runtu-desktop:~$ sudo chown -R bitcoin:bitcoin /etc/bitcoin
If this was not the case before on a running Bitcoin Node, the blockchain index needs to be rebuilt. Which means, shut down the Bitcoin service and start a full re-index. Since this can take again several hours or even days to complete its strongly recommended to run this in a screen session:
runtu@runtu-desktop:~$ sudo stop bitcoind
runtu@runtu-desktop:~$ sudo -u bitcoin \
bitcoind -conf=/etc/bitcoin/bitcoin.conf \
-datadir=/var/lib/bitcoind \
-daemon -server -disablewallet \
–reindex
IP Addresses & DNS Records
We use the same IP addresses and hostname as our Bitcoin node:
- 2001:db8::39 as global public IPv6 address;
- 192.0.2.39 as private local IPv4 address (port forwarded from the public IPv4 address);
- 198.51.100.240 as the ISP provided dynamic public Internet address;
Name Type Content Priority TTL
btc A 198.51.100.240 300
btc AAAA 2001:db8::39
Firewall Rules
Electrum Server listens on TCP ports 50001 and 50002 for incoming connections. Port 50001 is for plain unencrypted connections and port 50002 is TLS encrypted. We allow only secured connections on IPv4 and IPv6.
IPv4 NAT port forwarding:
Protocol Port No. Forward To Description
TCP 50002 192.0.2.39 Electrum Server TLS Connections
Allowed IPv6 connections:
Protocol Port No. Destination Description
TCP 50002 2001:db8::39 Electrum Server TLS Connections
Tor Hidden Service
We also use the same Hidden Service *.onion address for our BitCoin full Node and the Electrum Server. But since Electrum Server can not be persuaded to listen on multiple IP addresses (except all of them, which we don’t want), we tell the Tor client to proxy the eth0 IP 192.0.2.39 of the server instead of the usual localhost.
Add the following two highlighted lines to our Bitcoin Hidden Service by editing /etc/tor/torrc:
# BitCoin Full Node & Electrum Server Hidden Service for btc.example.net
HiddenServiceDir /var/lib/tor/hidden_services/bitcoin
HiddenServicePort 8333
HiddenServicePort 18333
HiddenServicePort 50001 192.0.2.39:50001
HiddenServicePort 50002 192.0.2.39:50002
Reload the Tor client:
runtu@runtu-desktop:~$ sudo service tor reload
The *.onion hostname is found in the file /var/lib/tor/hidden_services/bitcoin/hostname:
runtu@runtu-desktop:~$ sudo cat /var/lib/tor/hidden_services/bitcoin/hostname
duskgytldkxiuqc6.onion
Electrum Server User
For security reasons its best to run the server with its own unprivileged user profile. Create this user on the server system with the following command:
runtu@runtu-desktop:~$ sudo adduser --system --group --home /var/lib/electrum electrum
Software Installation
Software Dependencies
Electrum Server is a Python program and depends on various Python libraries:
runtu@runtu-desktop:~$ sudo apt-get install python-setuptools python-openssl python-leveldb libleveldb-dev
runtu@runtu-desktop:~$ sudo easy_install jsonrpclib irc plyvel
Download
The Electrum Server software is not available as installable software package. They don’t seem to release versions either. Instead the software is installed directly from the source code repository on GitHub:
runtu@runtu-desktop:~$ cd /var/lib/electrum
runtu@runtu-desktop:~$ sudo -Hu electrum git clone https://github.com/spesmilo/electrum-server.git
Install
You can see from the output below, that the next step takes several hours too. Because of the 13 GB database download.
runtu@runtu-desktop:~$ mkdir electrum-server
runtu@runtu-desktop:~$ cd electrum-server
runtu@runtu-desktop:~/electrum-server$ sudo ./configure
The Python installation script, will build and install the electrum-server executable in /usr/local/bin/electrum-server:
runtu@runtu-desktop:~$ sudo python setup.py install
Configuration
The installation script created a configuration file /etc/electrum.conf and filled parts of it for us, but it still needs a little bit of work:
[server]
# username for running the daemon
username = electrum
# hostname. set it to a FQDN in order to be reached from outside
host = localhost
# ports
electrum_rpc_port = 8000
stratum_tcp_port = 50001
stratum_tcp_ssl_port = 50002
report_host = btc.example.net
#report_stratum_tcp_port = 50001
#report_stratum_tcp_ssl_port = 50002
banner = Welcome to Electrum!
banner_file = /etc/electrum.banner
#irc = no
#irc_nick = <yournickname>
ssl_certfile = /etc/ssl/certs/example.net.chained.cert.pem
ssl_keyfile = /etc/ssl/example.net.key.pem
logfile = /var/log/electrum.log
donation_address =
[leveldb]
# path to your database
path = /var/lib/electrum/electrum-db
# for each address, history will be pruned if it is longer than this limit
pruning_limit = 100
[bitcoind]
bitcoind_host = localhost
bitcoind_port = 8332
# user and password from bitcoin.conf
bitcoind_user = bitcoinrpc
bitcoind_password = ********
The following steps are done as the electrum user in his home directory /var/lib/electrum on the server:
runtu@runtu-desktop:~$ sudo -u electrum -Hs
runtu@runtu-desktop:~$ cd ~
The FreeBSD Handbook - System Administrator
## Table Of Content ##
1. FreeBSD Getting Started Guide
2. PKG and Ports For Managing Software
3. Working with Files and Directories
4. Managing Users And Groups
5. Updating and Building the Kernel
6. Monitor Server Performance
Read Ebook
Author:
Linux BSD Blockchain - publish0x