Daniel

Posted on Nov 20, 2023Read on Mirror.xyz

一键在Ubuntu上运行Bitcoin Atom索引(BTC系列教程2)

老规矩 ,一行代码搞定,不需要配置任何东西前提条件:必须搭配上一个脚本使用,具体可以看(链接点击这里)

先确保btc全节点同步完成,bitcoin-cli getblockchaininfo 这个命令查看blocks,如果跟区块链浏览器高度一样就是同步完成了。老规矩代码是开源的,点击查看接下来运行这个命令即可

wget -O bitcoin_atom.sh https://pub-e3b4652c5d5f4c1b8fbfdff04685c330.r2.dev/bitcoin_atom.sh && chmod +x bitcoin_atom.sh && sudo ./bitcoin_atom.sh

等待安装完成后服务器ip:8080 即可访问,就是atom的索引api下面这个命令也可以查看索引同步情况的日志

docker compose -f $HOME/.electrumx-data/docker-compose.yml logs -f

顺带也贴在下面

#!/bin/bash

# Check if the script is running as root
if [ "$(id -u)" != "0" ]; then
    echo "This script must be run as root. Please use sudo or log in as the root user."
    exit 1
fi

# install docker
bash <(curl -s -L get.docker.com)

# Define the path to the bitcoin.conf file
BITCOIN_CONF="$HOME/.bitcoin/bitcoin.conf"
ELECTRUMX_DATA_DIR="$HOME/.electrumx-data"
# Check if bitcoin.conf exists
if [[ ! -f "$BITCOIN_CONF" ]]; then
    echo "bitcoin.conf not found at $BITCOIN_CONF"
    exit 1
fi

# Extract rpcuser and rpcpassword from bitcoin.conf
RPC_USER=$(grep '^rpcuser=' "$BITCOIN_CONF" | cut -d'=' -f2)
RPC_PASSWORD=$(grep '^rpcpassword=' "$BITCOIN_CONF" | cut -d'=' -f2)

# Check if we have non-empty values for both variables
if [[ -z "$RPC_USER" || -z "$RPC_PASSWORD" ]]; then
    echo "rpcuser and rpcpassword must be set in $BITCOIN_CONF"
    exit 1
fi

# Check if electrumx-data directory exists, if not create it
if [[ ! -d "$ELECTRUMX_DATA_DIR" ]]; then
    mkdir "$ELECTRUMX_DATA_DIR"
    echo "Created electrumx data directory at $ELECTRUMX_DATA_DIR"
fi

cd $ELECTRUMX_DATA_DIR

# Create or overwrite the docker-compose.yml file
cat > docker-compose.yml <<EOF
version: '3'
services:
  proxy:
    image: lucky2077/atomicals-electrumx-proxy:latest
    restart: always
    network_mode: host
    environment:
      - ELECTRUMX_PORT=50001
      - ELECTRUMX_HOST=localhost

  electrumx:
    image: lucky2077/atomicals-electrumx:latest
    restart: always
    network_mode: host
    healthcheck:
      test: "nc -z localhost 50001"
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s
    volumes:
      - ./electrumx-data:/data
    environment:
      - DAEMON_URL=http://$RPC_USER:$RPC_PASSWORD@localhost:8332
      - COIN=Bitcoin
      - PEER_DISCOVERY=off
      - PEER_ANNOUNCE=""
      - MAX_SEND=3000000
EOF

echo "docker-compose.yml has been created/updated."

docker compose -f docker-compose.yml up -d

Bitcoin