Electrs

Time: 30 minutes of work, then 12 hours to index.

The Road to Node gives you a choice between three different implementations of Electrum Server. With all three implementations you achieve the same thing, which is that you host an Electrum Server. They differ in development language, performance, and how public the servers are. Electrs differs from the rest because it is written in Rust. Performance-wise you should look up the differences between Electrum Personal Server, Elctrum X and Electrs.

Electrs waits for Bitcoin knots to finish synchronizing. So you can't use Electrs until the synchronization is done.

Installation

Start by installing the dependencies.

sudo apt install -y clang cmake cargo

Make sure you are in the home directory and get Electrs in via Git.

git clone https://github.com/romanz/electrs

Go into the Electrs directory.

cd electrs

Finally, install Electrs with Cargo.

cargo build --locked --release

Test if it works. The expected output is v0.10.0.

./target/release/electrs --version

Configuration

Electrs can be configured through a configuration file. Create it with mkdir ~/.electrs && mkdir ~/.electrs/db && nano ~/.electrs/config.toml. Then paste the following into the file.

cookie_file = "/home/ubuntu/.bitcoin/.cookie"
daemon_rpc_addr = "127.0.0.1:8332"
daemon_p2p_addr = "127.0.0.1:8333"
db_dir = "/home/ubuntu/.electrs/db"
network = "bitcoin"
electrum_rpc_addr = "0.0.0.0:50001"
log_filters = "INFO"

Save it with Ctrl + X and confirm with Y. You can check if it works with the same command as before: ./target/release/electrs. You should now see an output on your screen showing that Electrs has started indexing.

Firewall

The Electrum protocol communicates over a fixed set of ports. You can open 50001 if you want to talk to your Electrum Server using, for example, Sparrow wallet on your laptop.

sudo ufw allow 50001 comment "Port for Electrum Server"

If you want to monitor Electrs remotely you also need to open 4224. This is optional.

sudo ufw allow 4224 comment "Port for monitoring Electrs"

Automation

Electrs can also be automated so that it runs in the background and you don't have to start it manually. First create a service.

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

Put the following text in there.

[Unit]
Description=electrs
Requires=bitcoind.service
After=bitcoind.service
[Service]
WorkingDirectory=/home/ubuntu/electrs
ExecStart=/home/ubuntu/electrs/target/release/electrs
User=ubuntu
Group=ubuntu
Type=simple
Restart=on-failure
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 electrs
sudo systemctl start electrs

With systemctl status electrs you can see if everything is running properly and get an output similar to the one below.

- electrs.service - electrs
Loaded: loaded (/etc/systemd/system/electrs.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-01-14 20:36:59 UTC; 35s ago
Main PID: 67163 (electrs)
Tasks: 20 (limit: 4203)
CGroup: /system.slice/electrs.service
67163 /home/ubuntu/electrs/target/release/electrs

Updating

Go to the application directory.

cd ~/electrs

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 -f <OUTPUT FROM PREVIOUS STEP> # for example 0.10.0

Install the software.

cargo build --locked --release

Restart the Electrs service.

sudo systemctl restart electrs

Electrs is now updated! You may find that during the restart - something that can take several minutes - your node can't do anything else.