Setup Electrs

Install an Electrum server with Electrs.

An Electrum server is an indexing layer built on top of Bitcoin Core. It enables more efficient blockchain queries and easier wallet connections. Most wallets support Electrum.

We're going to use Electrs, a Rust implementation of an Electrum Server.

Install Electrs

Clone the repo:

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

Source the env file to update your $PATH with Rust & Cargo binaries:

. "$HOME/.cargo/env"

The binaries might already be in your PATH if Rust automatically added ."$HOME/.cargo/env" to your .profile, .bashrc, or .zshrc.

You can verify this with the command:

grep -H '.cargo/env' ~/.bashrc ~/.zshrc ~/.profile

Now you can compile electrs:

cd electrs
cargo build --locked --release

Once it's done, test the compilation was successful by checking the version:

~/electrs/target/release/electrs --version

Configure Electrs

Create the configuration file:

mkdir ~/.electrs && mkdir ~/.electrs/db && touch ~/.electrs/config.toml

Add the following configuration to the config.toml file we just created:

cookie_file = "/home/alex/.bitcoin/.cookie"
daemon_rpc_addr = "127.0.0.1:8332"
daemon_p2p_addr = "127.0.0.1:8333"
db_dir = "/home/alex/.electrs/db"
network = "bitcoin"
electrum_rpc_addr = "127.0.0.1:50001"
log_filters = "INFO"
  • cookie_file: Electrs can use the Bitcoin JSON-RPC API with cookie authentication.

  • daemon_rpc_addr: Bitcoin JSON-RPC API address and port.

  • daemon_p2p_addr: Bitcoin P2P address and port.

  • db_dir: Directory where Electrs store its index file.

  • electrum_rpc_addr: Electrum will run only on localhost, on port 50001.

Using 127.0.0.1 ensures that only locally running applications and Tor traffic can access our Electrum server.

Create Tor hidden service

We need to create a Tor hidden service to connect our wallets to the Electrum server. Edit the conf file:

sudo vim /etc/tor/torrc

Add the following:

HiddenServiceDir /var/lib/tor/electrs_hidden_service/
HiddenServicePort 50001 127.0.0.1:50001

Save it then restart tor:

sudo systemctl restart tor

Configure systemd service

Create the service file:

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

Add the following:

[Unit]
Description=electrs
Requires=bitcoind.service
After=bitcoind.service
[Service]
WorkingDirectory=/home/your_user/electrs
ExecStart=/home/your_user/electrs/target/release/electrs
User=your_user
Group=your_user
Type=simple
Restart=on-failure
TimeoutSec=120
RestartSec=30

[Install]
WantedBy=multi-user.target

Line 6,7,8 and 9 make sure to replace your_user by your own user. Finally, reload systemd:

sudo systemctl daemon-reload

Startup

Configure Electrs to automatically start at boot:

sudo systemctl enable electrs.service

Start Electrs:

sudo systemctl start electrs.service

Electrum will now connect to Bitcoin Core to build its own index of the blockchain.

Monitoring

Check the logs and monitor progress in real time:

journalctl -u electrs.service -f

Last updated

Was this helpful?