atomicals-electrumx

1. Install atomicals-electrumx

# use non-root user to deploy and execute electrumx server

# create electrumx_user or whatever username you like
sudo adduser electrumx_user

# add electrumx_user to sudo group
sudo usermod -aG sudo electrumx_user

# switch to electrumx_user
sudo su - electrumx_user

# prepare
sudo apt install python3-pip build-essential libc6-dev libncurses5-dev libncursesw5-dev libreadline-dev libleveldb-dev git -y
sudo pip3 install plyvel

# pull source code
git clone https://github.com/atomicals/atomicals-electrumx.git
cd atomicals-electrumx

# install electrumx server
sudo python3 setup.py install

# prepare
mkdir ~/.electrumx
mkdir ~/.electrumx/db
cd ~/.electrumx
openssl genrsa -out server.key 2048

# press Enter for prompt
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 1825 -in server.csr -signkey server.key -out server.crt

# create electrumx.conf 
nano ~/.electrumx/electrumx.conf

NET=mainnet
COIN=Bitcoin
DB_ENGINE=leveldb
DB_DIRECTORY=/home/electrumx_user/.electrumx/db
DAEMON_URL=http://<>:<>@localhost:8332
SSL_CERTFILE=/home/electrumx_user/.electrumx/server.crt
SSL_KEYFILE=/home/electrumx_user/.electrumx/server.key
SERVICES=tcp://:50001,ssl://:50002,wss://:50004,rpc://

# allow 50001 and 50002
sudo ufw allow 50001
sudo ufw allow 50001

2. Download ElectrumX-Data-807483

Note: This a public snapshot on iCloud. It's not uploaded or maintained by AnyNodes. https://www.icloud.com/iclouddrive/038z4LfgnnZtwLz5Kc3ERyQHw#ElectrumX-Data-807483

This step will download index db data till the block height 807,483. It can reduce the sync duration.

The backup data height is 807,483. It is where Atomicals started to index. If Atomicals upgrade their protocol, they will also start index from here.

To download the snapshot from the above iCloud url to your server, you need to generate the url with headers which includes a bearer token that valid about 40 minutes. Google how to generate the url.

We also uploaded the same copy to AnyNodes server. The following script will download the snapshot from https://anynodes.org/snapshots/atomicals/ElectrumX-Data-807483.zip

# switch to electrumx_user
su - electrumx_user

# the usual curl or wget are too slow to download large files. 
# thus we need to use the multi threads downloading tool aria2. 
# it will shrink the download duration from about 2 hours to 20 minutes.
# also install 7-zip which is faster than zip
sudo apt install aria2 p7zip-full -y

# download the backup data
# replace the value for direct_download_link if you want to use iCloud url
cd ~
direct_download_link='https://anynodes.org/snapshots/atomicals/ElectrumX-Data-807483.zip'
aria2c -x 16 -s 16 -o ElectrumX-Data-807483.zip $direct_download_link

mkdir -p ElectrumX-db-backup
# extract the .zip file. it will take about 15 minutes.
sudo 7z x /home/electrumx_user/ElectrumX-Data-807483.zip -o/home/electrumx_user/ElectrumX-db-backup -aoa

# change owner to electrumx_user
sudo chown -R electrumx_user:electrumx_user /home/electrumx_user/.electrumx/

# move files to db folder
sudo rm -rf /home/electrumx_user/.electrumx/db/*
sudo mv /home/electrumx_user/ElectrumX-db-backup/ElectrumX-Data-807483/* /home/electrumx_user/.electrumx/db/

3. Run electrumx as a service

# create service
sudo tee /etc/systemd/system/electrumx.service > /dev/null <<EOL
[Unit]
Description=Electrum X Server
Requires=bitcoind.service
After=network.target

[Service]
User=electrumx_user
EnvironmentFile=/home/electrumx_user/.electrumx/electrumx.conf
ExecStart=/home/electrumx_user/atomicals-electrumx/electrumx_server
Restart=always
TimeoutSec=120
RestartSec=30

[Install]
WantedBy=multi-user.target
EOL

# start service
sudo systemctl daemon-reload
sudo systemctl enable electrumx
sudo systemctl start electrumx

# check status
sudo systemctl status electrumx
sudo journalctl -u electrumx -f

It will take 2 days to catch up the latest block from block 807483.

After sync up, the bitcoin full node and electrumx server occupy 743 GB disk space. This is the figure on Jan 30th, 2024.

4. Update

sudo systemctl stop electrumx

sudo su - electrumx_user

cd ~/atomicals-electrumx
git fetch --all
git describe --tags `git rev-list --tags --max-count=1`
git checkout <OUTPUT FROM PREVIOUS STEP> # for example 1.16.0

# install the latest atomicals-electrumx
sudo python3 setup.py install
sudo systemctl start electrumx

# check status
sudo systemctl status electrumx
journalctl -u electrumx -f

If it does not work, may need to remove the current db, do step 2 again and start syncing from there.

Last updated