Skip to content

Instantly share code, notes, and snippets.

@transkatgirl
Last active January 19, 2025 18:54
Show Gist options
  • Save transkatgirl/6d24dcc6be6c19d0ac436bc72cfff363 to your computer and use it in GitHub Desktop.
Save transkatgirl/6d24dcc6be6c19d0ac436bc72cfff363 to your computer and use it in GitHub Desktop.
Setup an UnstoppableSwap Automated Swap Backend (sell XMR, receive BTC)

Setup an UnstoppableSwap Automated Swap Backend (ASB)

This script (tested on Ubuntu 24.10 & Ubuntu 24.04) allows you to anonymously perform the sell side of an UnstoppableSwap transaction (going from XMR to BTC).

Due to technical limitations, the sell side of an UnstoppableSwap transaction requires a long-lived server to perform the transaction. As a result, UnstoppableSwap-based XMR -> BTC transactions are only practical for large amounts.

  1. Setup a Monero node:
# Based on https://docs.getmonero.org/running-node/monerod-systemd/

sudo apt install -y monero

sudo sysctl -w vm.nr_hugepages=1280
echo "
vm.nr_hugepages=1280" | tee -a /etc/sysctl.conf

sudo useradd --system monero
sudo mkdir -p /etc/monero
sudo mkdir -p /var/lib/monero
sudo mkdir -p /var/log/monero
sudo chown monero:monero /etc/monero
sudo chown monero:monero /var/lib/monero
sudo chown monero:monero /var/log/monero

echo "data-dir=/var/lib/monero/bitmonero
prune-blockchain=1
sync-pruned-blocks=1

check-updates=disabled
enable-dns-blocklist=1
enforce-dns-checkpointing=1

p2p-use-ipv6=1
block-sync-size=100

log-file=/var/log/monero/monero.log
db-sync-mode=safe:sync" | sudo tee /etc/monero/monerod.conf

echo "[Unit]
Description=Monero Daemon
After=network-online.target

[Service]
ExecStart=monerod --detach --config-file /etc/monero/monerod.conf --pidfile /run/monero/monerod.pid
ExecStartPost=/bin/sleep 0.1
PIDFile=/run/monero/monerod.pid
Type=forking

Restart=on-failure
RestartSec=30

User=monero
Group=monero
RuntimeDirectory=monero

StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/monerod.service

sudo systemctl daemon-reload
sudo systemctl start monerod && sudo systemctl enable monerod
  1. Setup a Monero wallet RPC server:
echo '[Unit]
Description=Monero Wallet RPC Daemon
After=network-online.target

[Service]
Type=simple
ExecStart=monero-wallet-rpc --rpc-bind-port 18083 --disable-rpc-login --wallet-dir Monero --non-interactive --log-file .local/share/monero-wallet-rpc.log --log-level 1

Restart=on-failure
RestartSec=30

StandardOutput=journal
StandardError=journal

[Install]
WantedBy=default.target' | sudo tee /etc/systemd/user/monero-wallet-rpc.service

systemctl --user daemon-reload
systemctl --user start monero-wallet-rpc && systemctl --user enable monero-wallet-rpc
  1. Build the UnstoppableSwap ASB server from source:
sudo apt install -y git clang rustup

git clone https://github.com/UnstoppableSwap/core.git xmr-btc-swap

cd xmr-btc-swap

# Temporary hack to allow building on aarch64 linux
echo '
#[cfg(all(target_os = "linux", target_arch = "aarch64"))]
const DOWNLOAD_URL: &str =
    "https://downloads.getmonero.org/cli/monero-linux-armv8-v0.18.3.4.tar.bz2";
#[cfg(all(target_os = "linux", target_arch = "aarch64"))]
const DOWNLOAD_HASH: &str = "33ca2f0055529d225b61314c56370e35606b40edad61c91c859f873ed67a1ea7";' | tee -a swap/src/monero/wallet_rpc.rs

cargo build --release --package swap --bin asb && cp target/release/asb ..

cd ..
  1. Configure the ASB server (adjust the below configuration based on your risk tolerance):
mkdir -p ~/.config/xmr-btc-swap/asb/mainnet/
echo "[data]
dir = \"$HOME/.local/share/xmr-btc-swap/asb/mainnet\"

[network]
listen = []
# listen = [\"/ip4/0.0.0.0/tcp/9939\"]
rendezvous_point = [\"/dns4/discover.unstoppableswap.net/tcp/8888/p2p/12D3KooWA6cnqJpVnreBVnoro8midDL9Lpzmg8oJPoAGi7YYaamE\"]
external_addresses = []

[bitcoin]
electrum_rpc_url = \"ssl://blockstream.info:700\" # Publicly available Electrum servers can be found at https://github.com/spesmilo/electrum/blob/master/electrum/servers.json
target_block = 6
network = \"Mainnet\"

[monero]
wallet_rpc_url = \"http://127.0.0.1:18083/json_rpc\"
network = \"Mainnet\"

[tor]
register_hidden_service = true
hidden_service_num_intro_points = 20

[maker]
min_buy_btc = 0.001
max_buy_btc = 0.1
ask_spread = 0.05
price_ticker_ws_url = \"wss://ws.kraken.com/\"" | tee ~/.config/xmr-btc-swap/asb/mainnet/config.toml
  1. Wait for the Monero node to fully synchronize. Monitor the synchronization progress with the following command:
tail -f /var/log/monero/monero.log 
  1. Run the ASB server:
./asb start
  1. Deposit Monero into the printed deposit address, and wait for the ASB's Monero wallet to fully synchronize. You can monitor the wallet RPC server with the following command:
tail -f ~/.local/share/monero-wallet-rpc.log
  1. Restart the ASB server to update the wallet balance.

Backups

It is generally considered good practice to create backups of all wallets involved. Shutdown the ASB server before continuing.

  • Monero (press enter at the password prompt):
monero-wallet-cli --wallet-file Monero/asb-wallet --password "" seed
  • Bitcoin:
./asb export-bitcoin-wallet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment