#!/usr/bin/env bash # Skip stuck transactions by using the next available nonce # This allows new deployments to proceed even with stuck transactions 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 RPC_URL="${RPC_URL:-http://${RPC_CORE_1}:8545}" DEPLOYER="${DEPLOYER:-0x4A666F96fC8764181194447A7dFdb7d471b301C8}" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' CYAN='\033[0;36m' NC='\033[0m' log_info() { echo -e "${BLUE}[INFO]${NC} $1"; } log_success() { echo -e "${GREEN}[✓]${NC} $1"; } log_warn() { echo -e "${YELLOW}[⚠]${NC} $1"; } log_error() { echo -e "${RED}[✗]${NC} $1"; } log_section() { echo -e "\n${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"; echo -e "${CYAN}$1${NC}"; echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"; } echo "=== Skip Stuck Transactions ===" echo "" # Check RPC connectivity if ! timeout 5 cast chain-id --rpc-url "$RPC_URL" >/dev/null 2>&1; then log_error "RPC not accessible" exit 1 fi # Get nonce status log_section "Current Nonce Status" LATEST_HEX=$(cast rpc eth_getTransactionCount "$DEPLOYER" latest --rpc-url "$RPC_URL" 2>/dev/null | tr -d '"') PENDING_HEX=$(cast rpc eth_getTransactionCount "$DEPLOYER" pending --rpc-url "$RPC_URL" 2>/dev/null | tr -d '"') LATEST_DEC=$(cast --to-dec "$LATEST_HEX" 2>/dev/null || echo "0") PENDING_DEC=$(cast --to-dec "$PENDING_HEX" 2>/dev/null || echo "0") PENDING_COUNT=$((PENDING_DEC - LATEST_DEC)) echo "Latest nonce (confirmed): $LATEST_DEC" echo "Pending nonce (RPC reports): $PENDING_DEC" echo "Stuck transactions: $PENDING_COUNT" echo "" if [ "$PENDING_COUNT" -eq 0 ]; then log_success "No stuck transactions" echo "Next nonce to use: $((LATEST_DEC + 1))" exit 0 fi log_section "Recommendation" echo "To skip stuck transactions, use the NEXT nonce: $PENDING_DEC" echo "" echo "Example with cast send:" echo " cast send --nonce $PENDING_DEC --gas-price 10000000000 --rpc-url $RPC_URL" echo "" echo "Example with forge script:" echo " forge script