> For the complete documentation index, see [llms.txt](https://docs.money-printer-go-brrr.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.money-printer-go-brrr.com/readme/bitcoin-node/setup-your-bitcoin-node-from-source/setup-electrs.md).

# 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](https://github.com/romanz/electrs), a Rust implementation of an Electrum Server.

{% hint style="warning" %}
Make sure [Rust and Cargo are installed](/readme/bitcoin-node/setup-your-bitcoin-node-from-source/prepare-the-system.md#install-rust-and-cargo).
{% endhint %}

{% hint style="warning" %}
Make sure your node is [100% synchronized](/readme/bitcoin-node/setup-your-bitcoin-node-from-source/start-bitcoin-core.md#monitoring) before proceeding.
{% endhint %}

## Install Electrs

Clone the repo:

```bash
cd ~
```

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

Source the env file to update your <kbd>$PATH</kbd> with Rust & Cargo binaries:

```bash
. "$HOME/.cargo/env"
```

{% hint style="info" %}
The binaries might already be in your PATH if Rust automatically added `."$HOME/.cargo/env"` to your <kbd>.profile</kbd>, <kbd>.bashrc</kbd>, or <kbd>.zshrc</kbd>.&#x20;

You can verify this with the command:

`grep -H '.cargo/env' ~/.bashrc ~/.zshrc ~/.profile`
{% endhint %}

Now you can compile electrs:

```bash
cd electrs
```

```bash
cargo build --locked --release
```

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

```bash
~/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 <kbd>config.toml</kbd> file we just created:

{% hint style="warning" %}
With the configuration below the Electrum server will be accessible **only on localhost and on the Tor network**. Refer to [the configuration file on this page](https://theroadtonode.com/bitcoin-core-extensions/electrs#configuration) if you wish to also expose your node via IPv4/IPv6.
{% endhint %}

```toml
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"
```

* <kbd>cookie\_file</kbd>: Electrs can use the Bitcoin JSON-RPC API with [cookie authentication](/readme/bitcoin-node/setup-your-bitcoin-node-from-source/configure-bitcoin-core.md#json-rpc-api).
* <kbd>daemon\_rpc\_addr</kbd>: Bitcoin JSON-RPC API address and port.
* <kbd>daemon\_p2p\_addr</kbd>: Bitcoin P2P address and port.
* <kbd>db\_dir</kbd>: Directory where Electrs store its index file.
* <kbd>electrum\_rpc\_addr</kbd>: Electrum will run only on localhost, on port 50001.

{% hint style="info" %}
Using 127.0.0.1 ensures that only locally running applications and Tor traffic can access our Electrum server.
{% endhint %}

## Create Tor hidden service

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

```bash
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:

```bash
sudo systemctl restart tor
```

## Configure systemd service

Create the service file:

```bash
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 <kbd>your\_user</kbd> by your own user. Finally, reload systemd:

```bash
sudo systemctl daemon-reload
```

## Startup

Configure <kbd>Electrs</kbd> to automatically start at boot:

```
sudo systemctl enable electrs.service
```

Start <kbd>Electrs</kbd>:

```
sudo systemctl start electrs.service
```

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

{% hint style="success" %}
**Indexing is in progress. This operation may take 12 to 24 hours to complete.**
{% endhint %}

## Monitoring

Check the logs and monitor progress in real time:

```
journalctl -u electrs.service -f
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.money-printer-go-brrr.com/readme/bitcoin-node/setup-your-bitcoin-node-from-source/setup-electrs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
