#!/usr/bin/env bash # Fix RPC ChainID 138 + NPMplus: apply proxy config, then verify public RPC. # Run from repo root: ./scripts/fix-rpc-chain138-npmplus.sh # For NPMplus updates, run from same network as NPMplus (${NETWORK_PREFIX:-192.168.11}.x). # Requires NPM_PASSWORD in .env for NPMplus API updates. set -euo pipefail # Load IP configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" cd "$PROJECT_ROOT" # Load .env (set +u so values with $ in them don't trigger unbound variable) if [ -f .env ]; then set +u set -a # shellcheck source=/dev/null source .env 2>/dev/null || true set +a set -u fi echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🔧 Fix RPC ChainID 138 + NPMplus" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" # 1. Update NPMplus proxy hosts (RPC → VMID 2201) # Default .167: NPMplus (VMID 10233) is reachable on ${IP_NPMPLUS:-${IP_NPMPLUS:-192.168.11.167}}:81 (eth1); set NPM_URL in .env to override NPM_URL="${NPM_URL:-https://${IP_NPMPLUS}:81}" npm_reachable="" if curl -s -k -o /dev/null --connect-timeout 3 "$NPM_URL" 2>/dev/null; then npm_reachable=1; fi if [ -z "${NPM_PASSWORD:-}" ]; then echo "⚠️ Step 1: Skipped (NPM_PASSWORD not set)" echo " Set NPM_PASSWORD in .env to update NPMplus proxies." echo " Example: echo 'NPM_PASSWORD=your-password' >> .env" echo "" elif [ -z "$npm_reachable" ]; then echo "⚠️ Step 1: Skipped (NPMplus at $NPM_URL not reachable from this host)" echo " Run this script from a host on the same network as NPMplus (e.g. ${NETWORK_PREFIX:-192.168.11}.x)." echo "" else echo "📋 Step 1: Updating NPMplus proxy hosts..." if "$SCRIPT_DIR/nginx-proxy-manager/update-npmplus-proxy-hosts-api.sh"; then echo "" else echo "⚠️ NPMplus update had failures (auth or domain not found). Check output above." echo "" fi fi # 2. Verify public RPC echo "📋 Step 2: Verifying public RPC (eth_chainId)..." RPC_URL="https://rpc-http-pub.d-bis.org" RESP=$(curl -s -o /tmp/rpc-chain138-response.json -w "%{http_code}" -X POST "$RPC_URL" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' \ --connect-timeout 10 2>/dev/null || true) if [ "$RESP" = "200" ]; then CHAIN=$(jq -r '.result // empty' /tmp/rpc-chain138-response.json 2>/dev/null || grep -o '"result":"[^"]*"' /tmp/rpc-chain138-response.json 2>/dev/null | cut -d'"' -f4 || true) if [ "$CHAIN" = "0x8a" ]; then echo "✅ Public RPC OK: $RPC_URL → chainId 0x8a (138)" else echo "⚠️ RPC returned HTTP 200 but unexpected chainId: $CHAIN (expected 0x8a)" head -5 /tmp/rpc-chain138-response.json 2>/dev/null fi else echo "❌ Public RPC unreachable: $RPC_URL (HTTP $RESP or connect failed)" echo " Run from a host that can reach your NPMplus/public IP (e.g. same network)." echo " Check: DNS → NPMplus (10233) → Besu (2201). See docs/04-configuration/PUBLIC_RPC_CHAIN138_LEDGER.md" fi rm -f /tmp/rpc-chain138-response.json echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "Done." echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"